Add utilities for easier memory benchmarking.#27000
Add utilities for easier memory benchmarking.#27000CraigMacomber merged 6 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds higher-level utilities to help authors write correct Node.js memory benchmarks with fewer lifecycle/retention pitfalls, and adjusts the memory benchmarking defaults to be safer in the presence of finalizers.
Changes:
- Introduces
Box<T>,memoryAddedBy(...), andmemoryUseOfValue(...)to simplify common memory benchmark patterns. - Changes
MemoryUseBenchmark.enableAsyncGCdefault totrue, with targeted test updates to keep non-async-GC baselines. - Updates package exports, changelog, and API report to reflect the new public surface.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/benchmark/src/memoryBenchmarking/memoryUtils.ts | Adds new public helpers (Box, memoryAddedBy, memoryUseOfValue) for common memory benchmark authoring patterns. |
| tools/benchmark/src/memoryBenchmarking/getMemoryUse.ts | Switches default enableAsyncGC behavior and expands benchmarkMemoryUse docs to point to the new helpers. |
| tools/benchmark/src/memoryBenchmarking/index.ts | Re-exports the new memory benchmarking utilities from the memory benchmarking entrypoint. |
| tools/benchmark/src/memoryBenchmarking/configuration.ts | Updates guidance docs to mention the new helper APIs and Box for retention control. |
| tools/benchmark/src/index.ts | Exposes the new utilities from the package root entrypoint. |
| tools/benchmark/src/test/memoryBenchmarking/memoryUtils.spec.ts | Adds unit tests for Box and benchmark-based coverage/examples for the new helpers. |
| tools/benchmark/src/test/memoryBenchmarking/getMemoryUse.spec.ts | Pins enableAsyncGC: false for the “empty” baselines now that async GC defaults to true. |
| tools/benchmark/CHANGELOG.md | Documents the new utilities and the enableAsyncGC default change. |
| tools/benchmark/api-report/benchmark.public.api.md | Updates public API report to include the new exports. |
Comments suppressed due to low confidence (1)
tools/benchmark/src/memoryBenchmarking/getMemoryUse.ts:87
enableAsyncGCnow defaults totruehere, but the public TSDoc onMemoryUseBenchmark.enableAsyncGCinmemoryBenchmarking/configuration.tsstill says it defaults tofalse. Please update the documentation to match the new behavior so API docs don’t mislead benchmark authors.
const defaults: Required<Omit<MemoryUseBenchmark, "benchmarkFn">> = {
enableAsyncGC: true,
logProcessedData: false,
logRawData: false,
warmUpIterations: 12,
keepIterations: 10,
};
| * When implementing other cases, consider using {@link Box} to manage memory retention issues due to local variables. | ||
| * | ||
| * @public | ||
| * @input |
There was a problem hiding this comment.
I forget the exact semantics that @input intends to convey... this type does not satisfy them anymore because free functions return it, even if the functions are controlled by us and the returned object is only supposed to work as an input to other APIs in the package?
There was a problem hiding this comment.
This type is "input," meaning that code outside of the library defining it should not read from it. Future versions of this type may add optional members or make typing of members more general.
Since we never do non-breaking releases of benchmark, it doesn't really matter, so I figured we might as well allow people to read from the output of these new functions. I don't think that's really required if they are only passed right back into our own APIs as the same type or used with ... into the same type, but as we don't do non breaking releases, relaxing the rules seems fine.
| return this.inner; | ||
| } | ||
|
|
||
| public set value(v: T) { |
There was a problem hiding this comment.
| public set value(v: T) { | |
| /** | |
| * The value to store in the box. | |
| * @throws if the value is undefined. | |
| */ | |
| public set value(v: T) { |
There was a problem hiding this comment.
Do that and API extractor will complain the documentation is supposed to be on the getter instead.
Both share the same doc comment, in intellisense and API extractor.
There was a problem hiding this comment.
Huh, interesting. Ok, pretty minor.
|
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output |
## Description It is very easy to screw up writing memeory benchmarks. These changes make it much easier to get them right.
Description
It is very easy to screw up writing memeory benchmarks.
These changes make it much easier to get them right.
Reviewer Guidance
The review process is outlined on this wiki page.