You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: correct contrib jemalloc builds and C allocation slices - #505
Description
While testing optional jemalloc configurations, both contrib/demo jemalloc variants fail to compile because nodeSz is undefined. Define it from unsafe.Sizeof(node{}).
Replace the standalone reflect.SliceHeader conversion in contrib/memtest with unsafe.Slice, removing the existing go vet warning without converting a C pointer through uintptr.
Add bounded tests for node allocation/traversal/free, zero-initialized C allocations and byte accounting, and memory-reporting/list cleanup. Tests use small allocations rather than running the default multi-GiB memory-stress workload. The allocator-mode demo test temporarily uses a dedicated allocator and restores the original to support repeated test runs.
Checklist
Code compiles correctly and linting passes locally
Tests added for new functionality, or regression tests for bug fixes added as applicable
Local compilation and vet passed with go build ./... and go vet ./.... Repository-pinned Trunk 1.25.0 passed with trunk check --ci --no-progress --no-fix --upstream origin/main --print-failures: no issues across the four modified files. This is the repository-configured PR-scoped lint check.
Validation
Go 1.25.0; macOS arm64 default-mode contrib race tests and go vet ./... pass.
Linux arm64 container with jemalloc 5.3.0 built using --with-jemalloc-prefix=je_ --disable-shared --with-pic:
go test -count=1 -race ./contrib/...
go test -count=1 -race -tags jemalloc ./contrib/...
go test -count=1 -race -tags "jemalloc allocator" ./contrib/...
go vet ./...
All passed. Also tested in combination with #504: full uncached race suites and full-repository vet pass both with and without the jemalloc build tag. No tests of the original multi-GiB stress workload are claimed.
This cleanup is independent of #504 and can merge separately.
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by CodeRabbit
Refactor
Updated memory allocation handling while preserving allocation tracking.
Tests
Added checks for zero-initialized allocations, writable memory, allocation accounting, and cleanup.
Added lifecycle coverage for linked-node allocations and memory reporting, including verification that cleanup restores prior allocation counts.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 33803471-8a46-4423-be38-64ee007bd8cb
📥 Commits
Reviewing files that changed from the base of the PR and between 04f3117 and 27cca3f.
📒 Files selected for processing (3)
contrib/demo/node_test.go
contrib/memtest/main_test.go
contrib/memtest/nojemalloc.go
🚧 Files skipped from review as they are similar to previous changes (3)
contrib/demo/node_test.go
contrib/memtest/nojemalloc.go
contrib/memtest/main_test.go
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
Walkthrough
The changes define the demo node size and add a node lifecycle test. They also use unsafe.Slice to construct Calloc’s returned slice and add tests for allocation accounting and memory reporting.
Changes
Node Lifecycle Demo
Layer / File(s)
Summary
Node size and lifecycle test contrib/demo/node.go, contrib/demo/node_test.go
The demo defines nodeSz using unsafe.Sizeof. The test builds and prints a linked list, checks values from -1 through 14, and frees each node.
Calloc and Memory Reporting
Layer / File(s)
Summary
Calloc slice construction and accounting checks contrib/memtest/nojemalloc.go, contrib/memtest/main_test.go
Calloc uses unsafe.Slice instead of reflect.SliceHeader to construct its result. Tests check buffer length, capacity, zero initialization, allocation accounting, and memory reporting.
This change fixes contrib jemalloc builds and a go vet warning, and adds small tests. No merge-blocking risk is evident from the supplied context.
Pre-merge checks | 5
✅ Passed checks (5 passed)
Check name
Status
Explanation
Docstring Coverage
Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely identifies both main changes: fixing contrib jemalloc builds and correcting C allocation slice construction.
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
anirekhj
changed the title
Fix contrib jemalloc builds and C allocation slice construction
fix: correct contrib jemalloc builds and C allocation slices
Oct 10, 2026
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
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.
Description
While testing optional jemalloc configurations, both contrib/demo jemalloc variants fail to compile because nodeSz is undefined. Define it from unsafe.Sizeof(node{}).
Replace the standalone reflect.SliceHeader conversion in contrib/memtest with unsafe.Slice, removing the existing go vet warning without converting a C pointer through uintptr.
Add bounded tests for node allocation/traversal/free, zero-initialized C allocations and byte accounting, and memory-reporting/list cleanup. Tests use small allocations rather than running the default multi-GiB memory-stress workload. The allocator-mode demo test temporarily uses a dedicated allocator and restores the original to support repeated test runs.
Checklist
Local compilation and vet passed with
go build ./...andgo vet ./.... Repository-pinned Trunk 1.25.0 passed withtrunk check --ci --no-progress --no-fix --upstream origin/main --print-failures: no issues across the four modified files. This is the repository-configured PR-scoped lint check.Validation
Go 1.25.0; macOS arm64 default-mode contrib race tests and go vet ./... pass.
Linux arm64 container with jemalloc 5.3.0 built using --with-jemalloc-prefix=je_ --disable-shared --with-pic:
All passed. Also tested in combination with #504: full uncached race suites and full-repository vet pass both with and without the jemalloc build tag. No tests of the original multi-GiB stress workload are claimed.
This cleanup is independent of #504 and can merge separately.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit