Repository navigation
perf: use c allocator for shared io - #92
Merged
Merged
Conversation
wemeetagain
approved these changes
Nov 12, 2026
GrapeBaBa
pushed a commit
that referenced
this pull request
Nov 13, 2026
🤖 I have created a release *beep* *boop* --- ## [4.4.0](zapi-v4.3.0...zapi-v4.4.0) (2026-11-13) ### Features * **js:** add exact BigInt conversions, toI128LowBits and fromWords ([#91](#91)) ([b56bf2d](b56bf2d)) ### Performance Improvements * use c allocator for shared io ([#92](#92)) ([a736d8a](a736d8a)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
GrapeBaBa
added a commit
to ChainSafe/lodestar
that referenced
this pull request
Nov 13, 2026
…10612) **Motivation** `std.heap.page_allocator` maps at least one page per allocation and unmaps it on free, with no reuse. It fits large, long-lived buffers, but a few places in the Zig code use it for small per-call allocations. **Description** - `bindings/napi/pubkeys.zig`: keep `page_allocator` for the long-lived pubkey cache storage, including `pkix.load`, since `pkix.install` swaps the loaded storage and its allocator into the live cache. Per-call allocations (path strings, aggregate indices, `syncPubkeys` pointer arrays) now use `c_allocator`. - `PubkeyCache.syncPubkeys` takes a scratch allocator for its `prepared` and `batch_errors` arrays instead of borrowing the cache allocator. - `era.getShortEraRoot` takes an allocator from the caller instead of hardcoding `page_allocator`. The same issue in zapi's shared `std.Io.Threaded` (which allocates every `async`/`concurrent`/group task closure through its gpa) is fixed in ChainSafe/zapi#92. The zapi bump to 4.4.0 will land in a separate PR. **Testing** - `zig build test:state_transition test:era test:tidy` - `pnpm --filter @lodestar/native prepare-mainnet`, then binding tests `pubkeys`, `rewards`, `proposerRewards`, `attestationRewards` > This PR was written primarily by Claude Code. --------- Co-authored-by: Cayman <caymannava@gmail.com>
GrapeBaBa
added a commit
to ChainSafe/lodestar
that referenced
this pull request
Nov 13, 2026
**Motivation** zapi 4.4.0 includes ChainSafe/zapi#92: the shared `std.Io.Threaded` behind `js.io()` now allocates its `async`/`concurrent`/group task closures with `c_allocator` instead of `page_allocator`, so each task no longer costs an mmap/munmap pair. Follow-up to #10612. **Description** - Pin zapi to the `zapi-v4.4.0` tag commit `0cc6b2c`. - zapi 4.2.0 renamed `Number.toU64Exact` to `toSafeInteger` (ChainSafe/zapi#81) with unchanged semantics. Update the binding call sites. Other changes since the previous pin (4.1.0) are additive (`js.scratch()`, exact BigInt conversions). 4.2.0 also requires `setEnv`/`restoreEnv` to be paired; lodestar does not call them directly. **Testing** - `zig build test:tidy`, bindings build - `pnpm --filter @lodestar/native prepare-mainnet` and the full binding test suite: 26 files passed, 1 skipped (506 tests passed, 11 skipped) > This PR was written primarily by Claude Code.
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.
Motivation
The shared
std.Io.Threadeduses its allocator for temporary task and future allocations. Usingpage_allocatorsends those allocations directly through page mappings instead of allowing ordinary heap reuse.Description
Use
std.heap.c_allocatorfor shared I/O, matching the DSL's existing general-purpose allocator. The zapi module already links libc. This is an allocator-choice optimization; no performance improvement has been benchmarked.Verified with 45 Zig tests, the example addon build, and 136 JS DSL/addon-isolation tests. Changed-file formatting passes; whole-source formatting reports an existing issue in
src/create_callback.zig, also reproduced at the base revision.AI assistance: Codex prepared this change and ran the checks.