4 ms·
> Java has a ridiculously fast new operator. Much faster than the one in C++. Can you point us to some benchmarks? I don't doubt it is faster, but I doubt the
by pkolaczk 3y ago
> Java has a ridiculously fast new operator. Much faster than the one in C++.
Can you point us to some benchmarks?
I don't doubt it is faster, but I doubt the "ridiculously" part. Last time I measured it was only a tad faster than jemalloc (~20%) if you allowed the benchmark to run long enough for GC to start cleaning up. Unfortunately I haven't saved it (it was a very informal benchmark). I'm curios to see that esp. on modern low-pause GCs.
- the-smug-one 3y agoIt's just pointer bumping (still). If you're continously using new memory then soft page faults and finding physical backing via kernel will dominate. mallocsen want to avoid this scenario, so you often see malloc using more memory than necessary. Anyway, don't use new in C++ is my opinion.
- pkolaczk 3y agoIt's pointer bumping in optimistic case. Eventually it runs out of current slab and... then there is some more work to do. And also those page faults are actually quite likely as it gives you memory that hasn't been used recently. Malloc tends to return often whatever was released last that matches the requested allocation size. It is indeed a tad more work to find it, but when it's found it's usually hot in the cache.