Skip to content

La Famille / Field notes

Component Mapping & Micro-Improvement Audit: La Famille

Part 1: Component Identification

Here is a map of the major components currently residing in the internal/ directory and their core responsibilities based on the codebase structure:

Part 2: Micro-Improvements

Based on the architectural review, here are 3 to 5 localized, high-ROI micro-improvements that align with existing conventions and memory profiles:

  1. Optimize Struct Alignment (Memory Packing) Go’s fieldalignment tool identifies several key structs with poor field alignment, leading to wasted pointer bytes due to padding. Packing fields sequentially by size can significantly reduce garbage collection overhead on heavily instantiated structs. For example:

    • internal/generator/generator.go: SiteGenerator struct fields could be reordered to save 32 pointer bytes per instance (136 bytes down to 104 bytes).
    • internal/generator/cache.go: BuildCache struct could be reduced from 176 to 144 pointer bytes.
    • internal/config/config.go: Config struct could be optimized from 248 to 216 pointer bytes.
    • internal/retrieval/loader.go: The Document or Chunk structs could be packed to reduce memory overhead (96 pointer bytes to 80). Note: Applying field reordering requires manual review to ensure struct documentation comments are not stripped.
  2. Pre-allocate Maps and Slices During Graph & Taxonomy Building In both internal/graph/adjacency.go and internal/taxonomy/taxonomy.go, slices of keys are constructed from map iterations. While the slice length is often correctly pre-allocated via make([]string, 0, len(map)), the underlying maps constructed during AST traversal (e.g., when discovering links or tags) often start at size 0 and grow dynamically. Pre-allocating maps in internal/graph (where the number of edges is often known or bounded by the file size) or pre-allocating slices for deeply nested structs during internal/content/frontmatter.go parsing can yield small, measurable performance bumps in large workspaces.

  3. Improve Symlink Path Traversal Checks In internal/asset/copy.go (and potentially internal/content/), the system must safely copy files while preventing path traversal. Currently, relying solely on fs.FileMode checks is insufficient since FileMode doesn’t provide an IsSymlink() method. A micro-improvement is to explicitly apply the bitwise check info.Mode() & os.ModeSymlink != 0 within fs.WalkDir functions to strictly skip symlinks, ensuring robust directory boundaries without relying solely on final-path evaluations.

  4. Enhance Error Wrapping Context In areas handling file parsing and remote API connections, error context can be sparse. For instance, in internal/content/frontmatter.go when YAML unmarshaling fails, or in internal/github/github.go when API limits are hit, enhancing the errors with fmt.Errorf("parsing frontmatter for %q: %w", path, err) or standardizing API error wrappers provides significantly faster localized debugging compared to plain err.Error() string checks.

  5. Convert Linear Slice Scans to Map Lookups in Validation When the generator verifies reserved targets (in internal/generator/generator.go) or the stub generator checks if a slug is usable (internal/stub/stub.go), there is a pattern of converting a map to a slice of keys just to perform existence checks or sorting. By maintaining a centralized map[string]struct{} for claimed paths across the build lifecycle, the generator can perform O(1) map lookups instead of repeated O(N) linear array scans, especially valuable when processing thousands of internal tags and page links.