Skip to content

feat: replaced unsafe pointer with atomic.pointer[T] for cleaner atom…#152

Merged
guycipher merged 1 commit intowildcatdb:masterfrom
mehrdad3301:replace_unsafe_pointer
Feb 13, 2026
Merged

feat: replaced unsafe pointer with atomic.pointer[T] for cleaner atom…#152
guycipher merged 1 commit intowildcatdb:masterfrom
mehrdad3301:replace_unsafe_pointer

Conversation

@mehrdad3301
Copy link
Contributor

fixes issue.

Copy link
Member

@guycipher guycipher left a comment

Choose a reason for hiding this comment

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

Was there perf done to see if this solution has benefits on throughput and latency? Comparing benchmarks even to prior. I do wonder besides that the code looks great but I’m always curious on those perf aspects.

@mehrdad3301
Copy link
Contributor Author

mehrdad3301 commented Feb 13, 2026

I ran the default benchmarks and suprisingly there were some improvements

Benchmark Comparison: unsafe.Pointer vs atomic.Pointer[T]

Master Branch (unsafe.Pointer):

fillseq: 149,964.85 ops/sec
readrandom: 1,837,897.45 ops/sec
concurrent_writers: 154,459.93 ops/sec
Average: 219,194.10 ops/sec

Atomic.Pointer Branch:

fillseq: 159,338.64 ops/sec (+6.25% improvement)
readrandom: 1,985,226.34 ops/sec (+8.02% improvement)
concurrent_writers: 164,092.47 ops/sec (+6.24% improvement)
Average: 233,031.65 ops/sec (+6.31% improvement)

Performance Analysis:

fillseq: +6.25% faster (sequential writes)
readrandom: +8.02% faster (random reads)
concurrent_writers: +6.24% faster (concurrent writes)
Overall: +6.31% improvement in throughput

Latency Improvements:

fillseq P50: 12.5μs → 12.2μs (2.4% faster)
readrandom P50: 1.0μs → 875ns (12.5% faster)
concurrent_writers P50: 12.5μs → 12.7μs (similar)


I think that the Go compiler can optimize atomic.Pointer[T] better than manual unsafe.Pointer casts, leading to more efficient code generation. Another guess is that type-safe wrapper may improve memory layout and cache locality. I solely did this to improve code clarity, didn't think there were performance benefits associated

@mehrdad3301
Copy link
Contributor Author

I have no idea why the tests for windows are failing. Do you think it's related to this PR or something we need to investigate separately ? @guycipher

@guycipher
Copy link
Member

Good stuff, yeah windows is just generally slower the scheduler and stuff I think it may be a data race, I've reran with debug mode on. When I get to my computer I will pull your code and run it locally to see.

@guycipher
Copy link
Member

Was a data race.

@guycipher guycipher merged commit aa52722 into wildcatdb:master Feb 13, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use of unsafe pointer

2 participants