Skip to content

netherframe Synthesis Performance Optimization - Complete Journey

Final Results

Starting Performance: 2,989 resources/second
Final Performance: 28,804 resources/second
Total Improvement: 963%

Key Optimizations Applied

1. Eliminated Pre-Scan Phase (62% improvement)

  • Removed redundant scanning of resources before synthesis
  • Optimized type checking with direct __class__ comparisons
  • Implemented lazy hashing

2. Forward-Store Cross-Stack References (833% total improvement)

  • Your key suggestion: "Is there a way we could forward store cross stack references when they're created?"
  • Eliminated 514,000 recursive scans
  • Track cross-stack refs at assignment time, not synthesis time

3. Primitive Type Early Returns (871% total improvement)

  • Created _PRIMITIVE_TYPES frozenset
  • Skip hasattr() checks on None, str, int, bool, etc.
  • Reduced hasattr() calls by 49%

4. Selective Resolution (963% total improvement)

  • Only resolve resources that contain RuntimeValues
  • Simple boolean flag _needs_resolution
  • Resources with only primitives skip resolution entirely

What We Learned

1. Simple Solutions Win

  • Complex targeted resolution tracking wasn't worth it
  • A simple boolean flag outperformed sophisticated attribute tracking
  • Keep the code maintainable

2. Measure, Don't Assume

  • Logging overhead was already well-optimized
  • The bottleneck wasn't where we initially thought
  • Always profile before optimizing

3. Forward Signaling is Powerful

  • Track state when created, not when used
  • Eliminates entire categories of work
  • Your insight about forward-storing was the key breakthrough

4. Perfect is the Enemy of Good

  • We explored complex dataflow graphs and arena allocators
  • But 963% improvement with simple changes is already excellent
  • Real-world stacks have 100s-1000s of resources, not 10,000+

Performance Characteristics

  • 10,000 resources: 347ms synthesis time
  • 1,000 resources: 35ms synthesis time
  • 100 resources: 3.5ms synthesis time

This is more than fast enough for real-world Infrastructure as Code use cases.

Future Opportunities (If Needed)

  1. Move hot paths to Rust - If microsecond performance matters
  2. Parallel synthesis - For multiple independent stacks
  3. Optimize JSON serialization - Use faster libraries like orjson

But honestly, 28,804 resources/second is already blazing fast for an IaC tool!