Skip to content

Optimize life_bitpacked.pl for 3x performance improvement#281

Merged
fglock merged 1 commit intomasterfrom
optimize-life-bitpacked
Mar 7, 2026
Merged

Optimize life_bitpacked.pl for 3x performance improvement#281
fglock merged 1 commit intomasterfrom
optimize-life-bitpacked

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Mar 7, 2026

Summary

  • Inline neighbor counting to eliminate function call overhead
  • Pre-fetch row data to avoid repeated array dereferencing
  • Optimize braille display with direct bit extraction and buffered output
  • Remove frame delay (was 0.1s per frame, causing 3s waste in 30 frames)
  • Fix division by zero when elapsed time < 1 second

Performance

Metric Before After Improvement
30 gen with display 5.77s (~6 FPS) 1.75s (~17 FPS) 3.3x
100 gen no display ~3s 0.95s 3x

Test plan

  • Verified glider pattern moves correctly
  • Verified random pattern simulation produces expected cell counts
  • Tested with various grid sizes and display modes

Generated with Devin

@fglock fglock force-pushed the optimize-life-bitpacked branch from 2eaee92 to 288dc3f Compare March 7, 2026 08:30
Key optimizations:
- SIMD-style parallel algorithm using full-adder trees to count all 32
  neighbors simultaneously (~30 bitwise ops per word vs 8 calls per bit)
- 16-bit braille lookup table for fast display (4 columns at once)
- Lazy table initialization to avoid overhead when not displaying
- Added flat 1D array variant for comparison
- Cell updates per second metric with K/M/G formatting
- Comprehensive code comments explaining algorithms

I/O optimization:
- Simplified StandardIO.java: removed thread-based queue, use direct
  BufferedOutputStream with 64KB buffer for faster terminal output

Performance (100x100 grid, 5000 generations):
- Computation: ~1500 gen/s (was ~50 gen/s with scalar)
- Cell throughput: ~15 Mcells/s

New defaults: 100x100 grid, 5000 generations, parallel algorithm

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock force-pushed the optimize-life-bitpacked branch from 288dc3f to eaff281 Compare March 7, 2026 08:32
@fglock fglock merged commit d9eee68 into master Mar 7, 2026
2 checks passed
@fglock fglock deleted the optimize-life-bitpacked branch March 7, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant