Skip to content

perf: version based tracking and link reuse#26

Merged
brnrdog merged 2 commits into
mainfrom
version-based-tracking
Apr 21, 2026
Merged

perf: version based tracking and link reuse#26
brnrdog merged 2 commits into
mainfrom
version-based-tracking

Conversation

@brnrdog
Copy link
Copy Markdown
Owner

@brnrdog brnrdog commented Apr 20, 2026

Summary

  • Migrated scheduler internals to version-based dependency tracking with link reuse.
  • Kept lastDep as a true tail pointer and added per-run dependency cursors for fast reuse.
  • Added cursor ownership guards to avoid nested tracking edge cases.
  • Unified computed recompute flow in runComputedCycle and removed per-run full dep clears.
  • Fixed flush behavior to preserve effects queued during the same flush cycle.
  • Propagate from computeds only when value actually changes.
  • Defer effect propagation behind computed recompute only for computeds using custom ~equals.
  • Added a computed freshness fast path using global mutation version stamps.
  • Added signal notify fast path for direct-effect-only subscriber lists.
  • Replaced queue pre-scan sort checks with enqueue-time sort flags.
  • Split computed construction into fast path (no ~equals) and full path (custom ~equals).

API

  • Public API is unchanged.
  • Computed.make still supports optional ~equals.

Validation

  • npm run build && npm run test passes for both workspaces.

Benchmarks

  • Benchmark runs and detailed numbers are tracked in PR comments.
  • Includes:
    • ReScript Signals (main) vs ReScript Signals (current)
    • ReScript Signals vs selected top frameworks in milomg/js-reactivity-benchmark

Notes

  • Benchmark CI automation was extracted into a separate branch/PR (ci-benchmark-workflows) so it can be merged independently first.

@brnrdog brnrdog force-pushed the version-based-tracking branch from e5912de to 322f6cf Compare April 20, 2026 22:27
@brnrdog
Copy link
Copy Markdown
Owner Author

brnrdog commented Apr 21, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f6ed70abc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rescript-signals/src/signals/Scheduler.res Outdated
Comment thread packages/rescript-signals/src/signals/Scheduler.res Outdated
@brnrdog
Copy link
Copy Markdown
Owner Author

brnrdog commented Apr 21, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 76d6016a07

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rescript-signals/src/signals/Scheduler.res
@brnrdog brnrdog force-pushed the version-based-tracking branch from 218bdc5 to 7c7279b Compare April 21, 2026 12:32
@brnrdog
Copy link
Copy Markdown
Owner Author

brnrdog commented Apr 21, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c7279b396

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rescript-signals/src/signals/Scheduler.res Outdated
Comment thread packages/rescript-signals/src/signals/Scheduler.res Outdated
Comment thread packages/rescript-signals/src/signals/Scheduler.res Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

ReScript Signals benchmark: PR vs main

Compared implementations:

  • ReScript Signals (main)
  • ReScript Signals (PR)

Overall:

Version Total ms Avg ms/test
ReScript Signals (main) 17453.62 872.68
ReScript Signals (PR) 6057.93 302.90
Delta (ReScript Signals (PR) - ReScript Signals (main)) -11395.69 -65.29%

Per-test delta (lower is better):

Test Main ms PR ms Diff ms Diff %
2-10x5 - lazy80% 717.52 579.61 -137.92 -19.22%
25-1000x5 4756.91 1126.24 -3630.67 -76.32%
3-5x500 335.82 270.02 -65.80 -19.59%
4-1000x12 - dyn5% 7323.87 939.02 -6384.84 -87.18%
6-100x15 - dyn50% 581.51 458.63 -122.88 -21.13%
6-10x10 - dyn25% - lazy80% 470.09 350.76 -119.33 -25.38%
avoidablePropagation 321.14 316.41 -4.74 -1.48%
broadPropagation 305.23 235.38 -69.85 -22.88%
cellx1000 15.90 16.13 0.23 1.45%
cellx2500 47.04 44.67 -2.37 -5.03%
createComputations 214.40 299.02 84.62 39.47%
createSignals 3.50 3.59 0.09 2.71%
deepPropagation 107.53 107.57 0.04 0.04%
diamond 229.32 185.76 -43.56 -18.99%
molBench 45.02 44.93 -0.08 -0.18%
mux 427.06 269.06 -158.00 -37.00%
repeatedObservers 34.73 44.16 9.43 27.16%
triangle 77.07 60.31 -16.76 -21.75%
unstable 46.50 65.31 18.81 40.45%
updateSignals 1393.49 641.36 -752.12 -53.97%

Note: single-machine run in CI. Numbers can vary with runner load and Node/V8 version.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

Reactivity benchmark: PR vs top frameworks

Compared implementations:

  • Alien Signals
  • Preact Signals
  • SolidJS
  • Svelte v5
  • Vue
  • ReScript Signals (PR)

Overall ranking (lower total ms is better):

Rank Framework Total ms Avg ms/test
1 Alien Signals 4054.69 202.73
2 Preact Signals 4193.43 209.67
3 ReScript Signals (PR) 5497.12 274.86
4 Vue 5909.55 295.48
5 Svelte v5 8163.40 408.17
6 SolidJS 10638.23 531.91

Per-test runtime (ms):

Framework 2-10x5 - lazy80% 25-1000x5 3-5x500 4-1000x12 - dyn5% 6-100x15 - dyn50% 6-10x10 - dyn25% - lazy80% avoidablePropagation broadPropagation cellx1000 cellx2500 createComputations createSignals deepPropagation diamond molBench mux repeatedObservers triangle unstable updateSignals
Alien Signals 321.62 857.38 215.96 649.03 323.65 241.78 89.86 209.09 9.44 27.88 77.39 2.69 64.15 119.16 33.33 177.25 33.39 45.73 47.95 507.98
Preact Signals 392.88 871.31 213.01 680.89 344.58 264.95 92.54 210.91 9.71 31.13 73.09 2.07 74.11 122.93 33.17 182.45 20.35 45.69 34.15 493.50
ReScript Signals (PR) 490.79 955.07 267.14 703.15 369.60 323.04 296.06 292.17 15.97 58.68 291.99 3.40 102.46 176.05 46.52 276.85 39.70 52.86 61.26 674.37
Vue 550.80 1156.08 300.99 904.94 451.48 361.59 197.81 267.42 24.56 74.18 117.71 2.96 123.64 181.95 72.64 268.22 27.94 64.18 51.44 709.02
Svelte v5 1107.51 1192.50 300.55 1026.17 427.26 350.29 534.55 404.05 14.86 51.73 165.07 1.81 166.14 424.79 35.19 248.15 75.66 125.05 118.99 1393.06
SolidJS 2210.74 1650.95 510.65 1316.11 727.56 683.84 261.95 573.50 21.75 99.62 180.46 4.36 202.17 347.05 41.07 318.85 93.33 124.10 140.36 1129.82

Note: single-machine run in CI. Numbers can vary with runner load and Node/V8 version.

@brnrdog brnrdog force-pushed the version-based-tracking branch from a1291aa to e95b03d Compare April 21, 2026 17:33
@brnrdog
Copy link
Copy Markdown
Owner Author

brnrdog commented Apr 21, 2026

This is getting too big and complex, let's see if we can simplify these changes. Some of these performance improvements added too much complexity for a little gain. For example:

  • notifySubs fast path in Scheduler.res now does a pre-scan and may still fall back to full traversal. In mixed trees this can mean extra work and harder reasoning.
  • Sort guards (needsEffectSort / needsSubsSort) add another O(n) pass before processing each queue chunk. This may offset wins for medium queues.

@brnrdog
Copy link
Copy Markdown
Owner Author

brnrdog commented Apr 21, 2026

Good things to keep:

  • globalVersion + lastGlobalVersion skip in computed freshness is a good low-risk win.
  • Split computed constructor (equals vs no equals) for createComputations.
  • Keeping deferral aware of equality only for custom equals computeds is a good balance.

@brnrdog brnrdog marked this pull request as ready for review April 21, 2026 19:20
@brnrdog brnrdog force-pushed the version-based-tracking branch 2 times, most recently from 7376455 to afac55a Compare April 21, 2026 20:01
- Keep dependency links across runs and clean stale links by tracking
  version instead of full clear/rebuild.
- Add per-run dependency cursors and fast paths for computed/effect
  tracking to reduce fallback scans.
- Improve propagation/flush behavior with queue-draining fixes,
  selective computed deferral, and ordering optimizations.
- Add low-overhead freshness/notify fast paths (global version stamp,
  direct-effect notify path, computed-subscriber metadata).
@brnrdog brnrdog force-pushed the version-based-tracking branch from afac55a to 006acd7 Compare April 21, 2026 20:03
@brnrdog brnrdog merged commit 456f1c4 into main Apr 21, 2026
4 checks passed
@brnrdog brnrdog deleted the version-based-tracking branch April 21, 2026 20:26
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version rescript-signals-v3.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant