Skip to content

netherframe Performance Analysis Report

Executive Summary

Performance testing was conducted on the netherframe framework to measure stack creation and synthesis times with varying resource counts (10, 100, 1000, and 10000 resources). The analysis reveals significant performance bottlenecks in the synthesis phase that scale super-linearly with resource count.

Key Findings

Performance Metrics

Resources Total Time Creation Time Synthesis Time Per-Resource Memory Usage
10 0.061s 0.003s 0.036s 6.10ms 0.19 MB
100 0.347s 0.027s 0.299s 3.47ms 0.91 MB
1000 7.365s 0.626s 6.717s 7.37ms 5.94 MB
10000 72.043s 5.824s 66.197s 7.20ms 49.20 MB

Scaling Analysis

  • 10→100 resources (×10): Time scales ×5.7 (sub-linear, good performance)
  • 10→1000 resources (×100): Time scales ×120.7 (slightly super-linear)
  • 10→10000 resources (×1000): Time scales ×1180 (super-linear, needs optimization)

Critical Bottlenecks Identified

1. Synthesis Phase Dominates (91.9% at 10K resources)

The synthesis phase is the primary bottleneck, consuming: - 59% of total time at 10 resources - 86% of total time at 100 resources - 91% of total time at 1000 resources - 92% of total time at 10000 resources

Root Causes in Synthesis:

a) Hash Computation (_compute_hash)

  • 11.3 seconds at 10K resources
  • Called recursively 30,004 times (20,003 unique)
  • Likely computing hashes for deeply nested structures

b) Type Checking (isinstance calls)

  • 3.2 seconds of direct time
  • 39.6 seconds of cumulative time
  • 3.9 million calls at 10K resources
  • Heavy use in typing.__instancecheck__

c) JSON Serialization

  • The write_json step scales poorly with resource count
  • Likely serializing complex nested structures inefficiently

2. Resource Creation Shows Linear Scaling

Resource creation performance: - 10 resources: 3,146 resources/second - 100 resources: 3,740 resources/second
- 1000 resources: 1,596 resources/second - 10000 resources: 1,717 resources/second

The creation rate drops significantly at scale due to: - Logging overhead (1.5s at 10K resources) - Construct initialization overhead - Deferred binding pattern overhead

Recommendations for Optimization

Immediate Optimizations (High Impact)

  1. Optimize Hash Computation
  2. Cache computed hashes to avoid recomputation
  3. Use more efficient hashing for large structures
  4. Consider lazy hash computation

  5. Reduce Type Checking Overhead

  6. Cache isinstance results where possible
  7. Use direct type checks instead of typing module where appropriate
  8. Consider compile-time type checking only

  9. Optimize JSON Serialization

  10. Use faster JSON libraries (orjson, ujson)
  11. Stream JSON writing for large datasets
  12. Optimize object serialization with custom encoders

Medium-term Optimizations

  1. Reduce Logging Overhead
  2. Make logging conditional or batched
  3. Use lazy string formatting
  4. Consider log level-based filtering earlier in the pipeline

  5. Parallelize Synthesis

  6. Process independent resources in parallel
  7. Use multiprocessing for large resource counts
  8. Implement concurrent JSON writing

Long-term Architectural Changes

  1. Implement Incremental Synthesis
  2. Only recompute changed resources
  3. Cache synthesis results
  4. Implement differential updates

  5. Optimize Data Structures

  6. Use more efficient internal representations
  7. Reduce object nesting depth
  8. Implement copy-on-write for shared data

Performance Targets

Based on the analysis, achieving these targets would significantly improve user experience:

  • 1000 resources: Target < 2 seconds (currently 7.4s)
  • 10000 resources: Target < 10 seconds (currently 72s)

Focus should be on the synthesis phase, as optimizing it by 10x would bring the 10K resource case to ~7 seconds total.

Test Methodology

  • Test Environment: Python 3.13, local backend
  • Resource Type: Generic test resources with metadata, tags, and dependencies
  • Profiling Tools: cProfile, tracemalloc
  • Test Script: libs/netherframe.core/tests/performance/test_stack_synthesis_perf.py

Next Steps

  1. Profile the _compute_hash function in detail to understand recursion patterns
  2. Implement hash caching mechanism
  3. Benchmark alternative JSON serialization libraries
  4. Create targeted micro-benchmarks for each bottleneck
  5. Implement and measure optimizations iteratively