perf(kernel): replace module-level WeakMaps with intrusive symbol properties; add trimmed benchmark stats#79
Open
Copilot wants to merge 3 commits into
Open
perf(kernel): replace module-level WeakMaps with intrusive symbol properties; add trimmed benchmark stats#79Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
…hod closures Agent-Logs-Url: https://github.com/commoncurriculum/supergrain/sessions/4e14a25c-2299-4dc9-8bb3-750006c22799 Co-authored-by: scottmessinger <100121+scottmessinger@users.noreply.github.com>
…perties on targets Agent-Logs-Url: https://github.com/commoncurriculum/supergrain/sessions/4e14a25c-2299-4dc9-8bb3-750006c22799 Co-authored-by: scottmessinger <100121+scottmessinger@users.noreply.github.com>
… vs optimized) Agent-Logs-Url: https://github.com/commoncurriculum/supergrain/sessions/b2961eb9-de52-469f-8c59-8eaa8db08492 Co-authored-by: scottmessinger <100121+scottmessinger@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
scottmessinger
April 30, 2026 23:41
View session
There was a problem hiding this comment.
Pull request overview
This PR optimizes @supergrain/kernel hot paths by replacing several module-level WeakMap caches with intrusive, non-enumerable symbol properties on the proxied targets, and updates the js-krauset benchmark tooling to support trimmed statistics and Node compatibility.
Changes:
- Store
$PROXYand per-array$MUTATORScaches directly on raw targets (with WeakMap fallback for sealed/non-extensible objects). - Refactor reactive Map/Set implementations to use intrusive proxy caching and stable pre-created method wrappers.
- Update js-krauset perf scripts for Node compatibility and add
--trim Nto compute trimmed stats; adjust Vite aliases.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/kernel/src/read.ts | Adds $MUTATORS intrusive per-array wrapper cache; switches proxy caching to $PROXY with WeakMap fallback. |
| packages/kernel/src/core.ts | Introduces $MUTATORS well-known symbol. |
| packages/kernel/src/collections.ts | Removes dead keySignals WeakMap; adds $PROXY intrusive caching for Map/Set and pre-created stable method wrappers. |
| packages/js-krauset/vite.config.ts | Adds/adjusts alias ordering for kernel subpaths (/react, /internal). |
| packages/js-krauset/perf-stats.ts | Adds --trim support and Node-compatible dirname handling. |
| packages/js-krauset/perf-compare.ts | Fixes Node dirname handling and prints effective sample size. |
| packages/js-krauset/package.json | Switches perf scripts to npx tsx (but currently without declaring tsx); file formatting changed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
8
to
+13
| const name = process.argv[2]; | ||
| const runCount = parseInt(process.argv[3] || "15", 10); | ||
| // --trim N: drop N lowest and N highest values per metric before computing | ||
| // stats. Requires runCount > 2*N. Default 0 (no trimming). | ||
| const trimArg = process.argv.indexOf("--trim"); | ||
| const trimCount = trimArg !== -1 ? parseInt(process.argv[trimArg + 1] || "0", 10) : 0; |
Comment on lines
+10
to
+13
| "test:perf": "pnpm build-prod && vitest run --config vitest.dist.config.ts src/perf.test.ts --reporter=verbose 2>&1 | tee perf-results.txt", | ||
| "perf:stats": "npx tsx perf-stats.ts", | ||
| "perf:compare": "npx tsx perf-compare.ts", | ||
| "perf:profile": "pnpm build-prod && PROFILE=1 vitest run --config vitest.dist.config.ts src/perf.test.ts", |
Comment on lines
+2
to
+39
| "name": "js-framework-benchmark-react-supergrain", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build-prod": "vite build", | ||
| "typecheck": "tsc --noEmit", | ||
| "test": "pnpm build-prod && vitest run --config vitest.dist.config.ts src/dist.test.ts", | ||
| "test:perf": "pnpm build-prod && vitest run --config vitest.dist.config.ts src/perf.test.ts --reporter=verbose 2>&1 | tee perf-results.txt", | ||
| "perf:stats": "npx tsx perf-stats.ts", | ||
| "perf:compare": "npx tsx perf-compare.ts", | ||
| "perf:profile": "pnpm build-prod && PROFILE=1 vitest run --config vitest.dist.config.ts src/perf.test.ts", | ||
| "perf:analyze": "node perf-profile.ts" | ||
| }, | ||
| "dependencies": { | ||
| "@supergrain/kernel": "workspace:*", | ||
| "react": "19.2.4", | ||
| "react-dom": "19.2.4" | ||
| }, | ||
| "devDependencies": { | ||
| "@rollup/plugin-strip": "^3.0.4", | ||
| "@types/node": "^22.18.3", | ||
| "@types/ramda": "^0.31.1", | ||
| "@types/react": "^19.1.13", | ||
| "@types/react-dom": "^19.1.9", | ||
| "@vitejs/plugin-react": "^4.7.0", | ||
| "@vitest/browser": "4.1.0", | ||
| "playwright": "^1.55.0", | ||
| "ramda": "^0.32.0", | ||
| "typescript": "^5.9.2", | ||
| "vite": "^7.1.5", | ||
| "vite-plugin-dts": "^4.5.4", | ||
| "vitest": "4.1.0" | ||
| }, | ||
| "js-framework-benchmark": { | ||
| "frameworkVersionFromPackage": "react", | ||
| "frameworkHomeURL": "https://reactjs.org/" | ||
| } |
Copilot stopped work on behalf of
scottmessinger due to an error
May 1, 2026 12:06
Copilot stopped work on behalf of
scottmessinger due to an error
May 1, 2026 14:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--trim Nflag toperf-stats.ts--trim 3→perf-stats-baseline.jsonclaude/optimize-allocations-cW1Jm@d42fb15) iterations →perf-stats-claude-branch-v2.jsonResults: baseline vs updated claude/optimize-allocations-cW1Jm (d42fb15)
20 runs, trim 3 each end, n=14
Verdict: neutral / safe to merge. Every benchmark is within noise. The revert of the version-tagged elementCache fully resolved the
create-many-10kregression (+6.7% → +0.4% noise). The remaining structural refactors (combined For loops, consolidated node lookups, shared array mutators, hoistedArray.isArray,copyArrayInto) are all performance-neutral at this scale.