Skip to content

Use jemalloc as the global allocator#895

Merged
vinistock merged 1 commit into
mainfrom
vs_jemalloc
Jun 30, 2026
Merged

Use jemalloc as the global allocator#895
vinistock merged 1 commit into
mainfrom
vs_jemalloc

Conversation

@vinistock

Copy link
Copy Markdown
Member

Using jemalloc provides a 20% max RSS reduction and 15% speed up in total indexing + resolution time. It seems like an easy performance win and I think we should adopt it as the allocator on the Rust side.

Some relevant bits of the implementation:

  • Rubydex is meant to be used as a crate library as well and setting the global allocator can only happen during linking. In other words, there's no way to expose a function that someone can invoke to change the allocator, it has to happen at the top of the file statically. It wouldn't be conventional to have a library crate changing the default allocator since the consumer may want to decide what's the best allocator for their use case, so I gated this in a cargo feature
  • I did not go all the way to implement Track total memory used by the graph #864. We already have the new graph memory benchmark and tracking allocation stats is not free, so I decided against making the production build include it
  • Jemalloc is used in two different ways: for the Rust crate, it is statically linked. For the Ruby gem, since it uses dlopen to load the shared rubydex_sys object, we cannot do so and must dynamically load it as well. I gated this in a feature, so that direct consumers of the crate don't have to pay the performance cost of dynamic jemalloc load

Using jemalloc provides a 20% max RSS reduction
and 15% speed up in total indexing + resolution
time
@vinistock vinistock self-assigned this Jun 30, 2026
@vinistock vinistock requested a review from a team as a code owner June 30, 2026 14:39

@st0012 st0012 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With this change, will we be able to directly use jemalloc for more accurate memory measurement in --stats too?

@vinistock

Copy link
Copy Markdown
Member Author

Only if we include the stats feature in the jemalloc crate, but my understanding is that it's not completely free as it takes work to track all allocations and we'd not be able to turn it on only for main.rs and not for the rest.

My suggestion would be to rely on utils/bench-graph-memory and avoid enabling stats on the main crate.

@vinistock vinistock merged commit e6b7530 into main Jun 30, 2026
36 checks passed
@vinistock vinistock deleted the vs_jemalloc branch June 30, 2026 17:43
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.

2 participants