Skip to content

opt: skip allocation hot spots in elementify and handleScope#145

Open
mikesol wants to merge 2 commits intomainfrom
opt-sequential
Open

opt: skip allocation hot spots in elementify and handleScope#145
mikesol wants to merge 2 commits intomainfrom
opt-sequential

Conversation

@mikesol
Copy link
Copy Markdown
Owner

@mikesol mikesol commented Apr 13, 2026

Summary

Two sequential optimizations targeting allocation hot spots in 01_run1k (js-framework-benchmark):

opt3: skip fromParent+aref for leaf elements with empty children

  • Avoids 4 ST ref allocations (newStaticRegion) + 1 STRef.new(-1) per leaf element
  • The benchmark has ~2k leaf elements per 1k rows (empty td, span)
  • Result: ~455ms → ~391ms at this step, but see opt4 below

opt4: skip handleScope for elements with empty disposal queue

  • Adds isDisposalQueueEmpty to PSR (cheap array.length === 0 check)
  • handleScope skips pump + subscription setup when queue is empty — saves Event.create + 2 ST.new + subscribeO per skipped element
  • elementify/text skip addEffectToDisposalQueue for elements with an element parent (hasElementParent=true), since their removal handler is never reachable
  • ~5/9 elements per row skip the expensive handleScope path
  • Result: ~455ms → ~391ms (combined with opt3)

Test plan

  • Existing tests pass
  • Works in combination with purescript-hyrule#52 (merge PureAndEvent fix): ~134ms combined vs ~494ms unoptimized baseline

🤖 Generated with Claude Code

mikesol and others added 2 commits April 13, 2026 09:35
Avoids 4 ST ref allocations (newStaticRegion) + 1 STRef.new(-1) per
leaf element. Benchmark has ~2k leaf elements per 1k rows (empty td,
span). Result: 455ms median vs 494ms opt1 baseline (~7.7% gain).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add isDisposalQueueEmpty to PSR record (cheap: array.length check)
- handleScope now skips pump/subscription setup when queue is empty
- elementify/text skip handleRemove push for elements with element parent
  (hasElementParent=true means the lazy 'when false' handler is never called)

Combined effect: ~5/9 elements per row skip the expensive handleScope path
(Event.create + 2 ST.new + subscribeO per element). Saves ~64ms/1k rows.

Result: 391ms median vs 455ms opt3 baseline (~14% improvement).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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