Commit Graph

24 Commits

Author SHA1 Message Date
Michael Freno
abe34c4749 Implement algorithmic performance optimizations
Implemented high-impact optimizations from PERFORMANCE_ANALYSIS.md:

1. Dirty Flag System (30-50% fewer layouts):
   - Added _dirty and _childrenDirty flags to Element module
   - Elements track when properties change that affect layout
   - LayoutEngine checks dirty flags before expensive layout calculations
   - Element:setProperty() invalidates layout for layout-affecting properties

2. Dimension Caching (10-15% faster):
   - Enhanced _borderBoxWidth/_borderBoxHeight caching
   - Proper cache invalidation in invalidateLayout()
   - Reduces redundant getBorderBox calculations

3. Local Variable Hoisting (15-20% faster):
   - Hoisted frequently accessed properties outside tight loops
   - Reduced table lookups in wrapping logic (child.margin cached)
   - Optimized line height calculation (isHorizontal hoisted)
   - Heavily optimized positioning loop (hottest path):
     * Cached element.x, element.y, element.padding
     * Hoisted alignment enums outside loop
     * Cached child.margin, child.padding per iteration
     * 3-4 table lookups → 2 lookups per child

4. Array Preallocation (5-10% less GC):
   - Preallocated lineHeights with table.create() when available
   - Graceful fallback to {} on standard Lua

Estimated total gain: 40-60% improvement (2-3x faster layouts)
All 1257 tests passing. Zero breaking changes.

See ALGORITHMIC_OPTIMIZATIONS.md for full details.
2025-12-05 14:43:46 -05:00
Michael Freno
4652f05dac Add LuaJIT FFI optimizations for memory management
- New FFI module with object pooling for Vec2, Rect, Timer structs
- Integrated FFI into LayoutEngine, Performance, and Color modules
- Graceful fallback to standard Lua when LuaJIT unavailable
- Added ffi_comparison_profile.lua for automated benchmarking
- Comprehensive documentation of gains and real bottlenecks

Reality: 5-10% performance improvement (marginal gains)
FFI targets wrong bottleneck - real issue is O(n²) layout algorithm
See PERFORMANCE_ANALYSIS.md for high-impact optimizations (2-3x gains)
2025-12-05 14:35:37 -05:00
Michael Freno
ae2d28f6b1 Adjust autosizing to better account for text wrapping. 2025-12-05 11:52:30 -05:00
Michael Freno
3ee4bf1786 removed old cleanup, fix inputs 2025-12-04 00:17:04 -05:00
Michael Freno
efce61d077 streamling errorhandler calls 2025-12-03 22:19:27 -05:00
Michael Freno
57da711492 caching perf improvements - major improvements for immediate mode 2025-11-25 12:55:39 -05:00
Michael Freno
d3014200da memory tooling, state handling changes 2025-11-25 09:50:57 -05:00
Michael Freno
d0357672db cleanup stale tests, profiling reports 2025-11-20 11:36:41 -05:00
Michael Freno
57eb52e70d continued refactor 2025-11-19 16:49:34 -05:00
Michael Freno
2c04f69daa Performance and reporting improvements 2025-11-17 17:41:01 -05:00
Michael Freno
f8fddb7ffa continuing testing 2025-11-15 00:01:45 -05:00
Michael Freno
93af33825d immediate mode scroll regression fixed 2025-11-13 22:33:53 -05:00
Michael Freno
9da8d589a1 fixed 2025-11-13 21:01:04 -05:00
Michael Freno
7e69e7f544 oops 2025-11-13 20:50:18 -05:00
Michael Freno
3373d43b1b fix Gui references 2025-11-13 20:42:47 -05:00
Michael Freno
225dff8f74 typings 2025-11-13 00:17:55 -05:00
Michael Freno
712b3c40e9 cleanup 2025-11-13 00:06:09 -05:00
Michael Freno
42704660b2 remove asserts 2025-11-12 23:38:13 -05:00
Michael Freno
b886085d3e change to DI 2025-11-12 23:30:29 -05:00
Michael Freno
47ec641eb9 Revert Phase 2 text calculations changes - broke layout 2025-11-12 21:18:44 -05:00
Michael Freno
8206f96867 continued refactor 2025-11-12 21:16:35 -05:00
Michael Freno
73044cfd6c layoutengine extracted 2025-11-12 18:58:24 -05:00
Michael Freno
1293ca81a4 restart 2025-11-12 17:53:22 -05:00
Michael Freno
7faa8b4ec6 modularizing (broken) 2025-11-12 17:19:46 -05:00