Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom allocators #297

Open
lquerel opened this issue Aug 13, 2024 · 6 comments
Open

Support for custom allocators #297

lquerel opened this issue Aug 13, 2024 · 6 comments

Comments

@lquerel
Copy link

lquerel commented Aug 13, 2024

I’d like to propose adding features to support mimalloc and jemalloc. Regorus is typically a CPU and memory-bound system, so it makes sense to use allocators that are more efficient than the standard ones. I’ve seen significant performance gains in several of my projects simply by enabling this type of allocator. It seems worthwhile to support this, especially for the bindings, as it doesn’t appear that it can be easily done without modifying the binding code.

I can create a PR if the maintainers of this project are interested in the idea.

@anakrish
Copy link
Collaborator

@lquerel Thanks for the proposal. I agree that it will be in general be beneficial to support custom allocators. Please do create a PR.

@lquerel
Copy link
Author

lquerel commented Aug 20, 2024

@anakrish I did a quick and dirty test with the standard allocator, mimalloc, and jemalloc (see the screenshot below, env: macos). Without any concurrency, the results were very close, with a slight advantage for mimalloc. However, after modifying the regorus CLI (examples) and running 100 tasks in parallel, the differences between the allocators became clearly apparent. This was expected, as mimalloc, in particular, is optimized for multithreaded environments.

I recommend always enabling mimalloc for the bindings since there is no disadvantage to using it in single-threaded scenarios, and there is a significant advantage in scenarios involving multiple policy evaluations in parallel, which I believe is a common use case in production. What do you think?

image

@anakrish
Copy link
Collaborator

@lquerel Thanks for performing the experiments. The performance benefits look great! Would it be possible to also try out https://github.com/schrodingerzhu/snmalloc-rs? It is an allocator that should perform well in multi-threaded scenarios.

I recommend always enabling mimalloc for the bindings since there is no disadvantage to using it in single-threaded scenarios, and there is a significant advantage in scenarios involving multiple policy evaluations in parallel, which I believe is a common use case in production. What do you think?

I concur. However, it would be great if the allocator was made configurable so that users can choose the allocator that they favor.

@lquerel
Copy link
Author

lquerel commented Aug 20, 2024

@anakrish It looks like mimalloc and snmalloc are equivalent in terms of performance for this scenario.

image

I will create a PR later today with a set of cargo features.

@anakrish
Copy link
Collaborator

@lquerel Thanks!

@anakrish
Copy link
Collaborator

@lquerel You'd already have likely seen this:

#[cfg(feature = "custom_allocator")]

This is mainly used for no_std environments and is currently not exposed to the different bindings.

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

No branches or pull requests

2 participants