squirrelworks

Computer Science Foundations > Part 2: Runtimes, ASTs & Applied Data Structures

A SysAdmin's Guide to Computer Science: Runtimes, ASTs & Data Structures

Once hardware memory models and algorithmic complexity ($O(n)$) are understood, the next layer of computer science focuses on software execution: how source code parses into syntax trees, how interpreters and compilers generate machine opcodes, and how data structures shape disk and RAM performance.

AST Parsing & Lexing Garbage Collection Pauses B-Trees & Ring Buffers
cs-core — part 2 runtimes
Lexer: Tokenizing Source Text
AST: Parsing Syntax Trees
Runtime: JIT & Garbage Collection
Goal: Zero-Fluff Execution Mechanics

1. The Parsing Pipeline: Lexers, Tokens & Abstract Syntax Trees

Computers cannot evaluate raw text strings like if ($status == 200) directly. Every language runtime—whether compiling C code or parsing a YAML configuration file in Ansible—executes a two-step parsing pipeline before any execution occurs.

sequenceDiagram
    autonumber
    actor Source as Raw Source Text
    participant Lexer as Lexical Analyzer (Tokenizer)
    participant Parser as Syntactic Parser
    participant AST as Abstract Syntax Tree (AST)
    participant Emitter as Bytecode / Native Code Generator

    Source->>Lexer: 1. Pass raw characters (e.g. "if (x > 5)")
    Lexer->>Parser: 2. Emit linear stream of Tokens (IF, LPAREN, IDENT, GT, INT)
    Parser->>AST: 3. Construct hierarchical tree based on grammar rules
    AST->>Emitter: 4. Traverse tree nodes to generate machine opcodes or bytecode
                
1. Lexical Analysis (Tokenization)

The Lexer scans source code character-by-character, stripping whitespace and comments, and converts text into a flat array of classified Tokens (Keywords, Operators, Identifiers).

2. Syntactic Analysis (AST Generation)

The Parser validates token order against a formal context-free grammar, building an Abstract Syntax Tree (AST). Syntax errors in Nginx, C, or Python fail at this exact tree-building stage.

Tech Fact Icon
DevOps Takeaway

Infrastructure linters (like tflint, ansible-lint, or ShellCheck) don't run your scripts—they construct an AST from your files and evaluate the tree against static security and syntax rule sets.

2. Execution Models & Application Binary Interfaces (ABI)

Once an AST is constructed, how the binary or script executes against CPU registers depends entirely on its runtime model.

Execution Model Translation Mechanics Operational DevOps Impact
Ahead-Of-Time (AOT)
Go, Rust, C/C++
Compiles AST directly into architecture-specific binary opcodes before runtime execution. Produces ultra-fast, standalone binaries with zero external runtime dependencies—ideal for minimal Docker containers.
Interpreted / Scripted
Bash, Python, PHP
Evaluates AST or bytecode line-by-line via a virtual machine process (Zend, CPython). Allows rapid scripting and live hot-reloading, but introduces interpreter CPU overhead and dependency management.
Just-In-Time (JIT)
Java (JVM), Node.js (V8)
Compiles bytecode into native machine code on-the-fly during execution based on active usage profiles. Delivers near-native execution speed, but requires significant initial startup time ("warm-up period") and higher RAM reserves.

Static vs Dynamic Linking

Static compilation bundles all C/system libraries into the binary. Dynamic linking (.so / .dll) relies on system runtime libraries—saving disk space but introducing dependency breaks.

ABI Breakage in Alpine Linux

Running a C/Go binary compiled for GNU glibc on an Alpine Linux container fails with No such file or directory because Alpine uses the lightweight musl C library ABI.

3. Managed Runtimes: Garbage Collection (GC) & Latency Spikes

As explored in Part 1, unmanaged languages (C/C++) require explicit memory allocation and freeing (malloc / free). Managed runtimes (Java, Go, Node.js, Python) automate Heap memory management using background Garbage Collection (GC) engines.

Mark-and-Sweep
Tracing Heap Objects from Root References

The GC starts at root pointers (Stack variables) and traverses all connected Heap references ("Marking"). Unreachable objects are swept away to reclaim RAM.

Stop-The-World (STW)
The Source of Mysterious Server Latency Spikes

To safely update memory pointers, older GC algorithms temporarily freeze all active execution threads ("Stop-The-World"). In large Java or Elasticsearch nodes with 32GB+ heaps, STW pauses can freeze application response times for several seconds.

Generational GC & Tri-Color Marking
Modern Low-Latency Garbage Collection

Modern runtimes (Go's concurrent GC or Java's ZGC) split Heap objects by age ("Young" vs "Tenured" generations) and sweep memory concurrently alongside active application threads—dropping GC pauses to under 1 millisecond.

4. Applied Data Structures: B-Trees, LSM-Trees, Queues & Hashes

In systems administration, selecting or tuning datastores requires knowing how underlying data structures organize bytes on physical disk and in RAM.

Data Structure Storage & Access Characteristics Production Infrastructure Role
B-Trees / B+Trees Self-balancing multi-way search trees optimized for reading block storage (O(log n)). Relational database indexing (MySQL InnoDB, PostgreSQL) and OS file systems (Ext4, XFS).
LSM-Trees (Log-Structured Merge) Buffers writes in RAM memtables before flushing sequentially to disk immutable files. Write-heavy NoSQL databases (Cassandra, RocksDB, Prometheus TSDB).
Ring Buffers (Circular Queues) Fixed-size array with wrapping head/tail pointers for zero-allocation FIFO streaming. Linux kernel network socket buffers (e.g., NIC packet reception queues).
Hash Tables & Tries Converts keys to array indices for instant O(1) access; Trie trees match string prefixes. In-memory caches (Redis, Memcached) and IP CIDR route lookup tables in switches.
B-Trees vs LSM-Trees: The Read/Write Trade-off

B-Trees require random disk writes to update existing nodes, making them ideal for fast, multi-column SELECT queries. LSM-Trees convert all updates into fast sequential append-only writes, making them the architecture of choice for high-volume telemetry, logging, and metrics storage.

5. Summary: Bridging Language Runtimes & Data Storage

Understanding how language parsers turn code into ASTs, how garbage collectors sweep heap memory, and how datastores manage B-Trees and ring buffers demystifies software behavior under heavy load.

Part 2 Execution & Storage Architecture Complete
Syntax Engine: Lexer → Tokens → AST Parsing
Execution Layer: AOT Binaries, JIT Warm-up & ABI Compatibility
Memory Lifecycle: Mark-and-Sweep GC & Stop-The-World Pauses
Datastore Mechanics: B-Trees (Reads) vs LSM-Trees (Writes)
Next Step: Distributed Systems & Network Protocols

With continuous math, OS memory models, language runtimes, and datastore structures mapped, the final piece of the puzzle is connecting systems together over an unreliable network. In Part 3, we explore TCP state machines, TLS 1.3 handshakes, CAP theorem trade-offs, and Raft consensus mechanics in distributed clusters.



Accessibility
 --overview

API
 --REST best practices
 --REST demo
 --REST vs RPC
 --Wikipedia API

Blockchain
 --overview

Blog
 --The 'Brute Force' Mistake
 --The Bezosian Protocol: Eliminating Learned Helplessness
 --The Humility Protocol: Reality Over Reputation
 --The Jobsian Protocol: Systems Analysis as a War on Entropy
 --The Jordan Framework: Engineering a Competitive Edge
 --Time Management as an Operational System: The Tracy Framework
 --Tracy on Goals: Vector Alignment & Execution

Cloud
 --AWS overview

CSS/HTML
 --Admissions Portal Simulation Lab
 --Bootstrap carousel
 --Grid demo
 --markdown demo

DevOps
 --Agile Principles
 --DevOps overview
 --Drupal, containerized
 --Prometheus & Grafana
 --RKE2: Deploying the Rancher Kubernetes Engine

Encoding
 --Overview

Ergonomics
 --Desk configuration
 --Device fleet
 --Input device array
 --keystroke mechanics
 --Phones & RSI

ERP
 --Anthology overview
 --Ellucian Banner
 --Higher Ed ERP Simulation Lab
 --PeopleSoft Campus Solutions
 --PESC standards
 --Slate data model

Git
 --Authoring & Deploying the Post-Receive Hook
 --syntax overview
 --troubleshooting libcrypto

Hardware
 --Device fleet
 --Electricity fundamentals
 --Homelab diagram

Identity & Access
 --Deploying Entra Connect
 --Foundations
 --OIDC Integration
 --Provisioning Okta Dev Tenant

Java
 --Fundamentals

Javascript
 --Advanced Interaction: jQuery & UI Frameworks
 --input prompt demo
 --misc demo
 --Time and Date functions
 --Vue demo

Linux
 --Auditing the live interface state using ethtool
 --grep demo
 --HCI and Proxmox
 --Persistent Infrastructure Telemetry: TMUX
 --Proxmox install
 --xammp ftp server

Mail flow
 --DKIM, SPF, DMARC
 --MAPI

Microsoft
 --AZ-800: Administering Windows Server Hybrid Core Infrastructure
 --BAT scripting
 --Group Policy
 --IIS
 --robocopy
 --Server 2022 setup - Virtualbox

Misc
 --Applications
 --Computer Science Foundations
 --Field Notes: RainPoint Bluetooth Hose Timer
 --Protocols, TLS & Distributed Scale
 --regex
 --Resources
 --Runtimes, ASTs & Data Structures
 --Sustainable Computing
 --Terminology
 --Tribute to Computer Scientists

Networks
 --BGP Peering & Security Hardening Lab
 --CCNA Lammle Study Guide
 --Cisco 1921/K9 router
 --NGFW vs. Legacy
 --routing protocols
 --throughput calculations

PHP/SQL
 --Cookies
 --database interaction
 --demo, OSI Layers quiz
 --Foreign key constraint demo
 --fundamentals
 --MySQL and PHPmyAdmin setup
 --pagination
 --security
 --session variables
 --SQL fundamentals
 --structures
 --Tables display

Python
 --fundamentals

Security
 --Kerberos: Protocol Architecture
 --NTP Overview
 --Overview- GRC (Governance, Risk, and Compliance)
 --Security Blog
 --SSH fundamentals

Serialization
 --JSON demo
 --YAML demo