Skip to content

Allow setting pooling allocation in the C API #10484

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

Merged
merged 7 commits into from
Mar 31, 2025

Conversation

fridaymore
Copy link
Contributor

@fridaymore fridaymore commented Mar 28, 2025

We are troubleshooting performance / scaling issues in our project that uses Wasmtime and Pooling Allocation was recommended. Currently, we are not able to enable Pooling Allocation through the C API.

Note: mpk options are not exposed.

@fridaymore fridaymore requested a review from a team as a code owner March 28, 2025 16:47
@fridaymore fridaymore requested review from dicej and removed request for a team March 28, 2025 16:47
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks! Would you be up for refactoring this to use an object-style API along the lines of wasm_config_t where a new wasmtime_pooling_config_t object was added and the properties here are functions to configure each field? That way it's possible to configure just a single option while leaving all the others at their defaults, while currently it would require configuring all options at the same time.

Additionally as a minor thing, mind putting #ifdef guards around these definitions for the pooling allocator cfg being turned on?

@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Mar 28, 2025
@fridaymore
Copy link
Contributor Author

Thanks! Would you be up for refactoring this to use an object-style API along the lines of wasm_config_t where a new wasmtime_pooling_config_t object was added and the properties here are functions to configure each field? That way it's possible to configure just a single option while leaving all the others at their defaults, while currently it would require configuring all options at the same time.

Additionally as a minor thing, mind putting #ifdef guards around these definitions for the pooling allocator cfg being turned on?

Thanks - I switched to an object-style API and added the #ifdef guards for feature gating. Can you opine on memory management for wasmtime_pooling_config_t? I am assuming I need to provide a way to free the memory that was allocated on the heap?

@alexcrichton
Copy link
Member

Yeah adding a free method for it I think is the way to go. Otherwise "cloning out" the configuration makes sense to me as well.

Mind also adding wasmtime_* prefixes to the methods/types here too?

@fridaymore
Copy link
Contributor Author

Pushed some changes, please take another look.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks! Just some minor things here and there, but otherwise looks good

WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(total_gc_heaps, uint32_t)

WASM_API_EXTERN void wasmtime_pooling_allocation_strategy_set(
wasm_config_t *, wasmtime_pooling_allocation_config_t *);
Copy link
Member

Choose a reason for hiding this comment

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

For this I think the second argument can be const wasmtime_pooling_allocation_config_t* to reflect how it doesn't mutate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

WASM_API_EXTERN void wasmtime_pooling_allocation_strategy_set(
wasm_config_t *, wasmtime_pooling_allocation_config_t *);

#endif
Copy link
Member

Choose a reason for hiding this comment

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

Mind adding a // WASMTIME_FEATURE_POOLING_ALLOCATOR here to indicate which #ifdef it's closing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 547 to 554
typedef struct wasmtime_pooling_allocation_config_t
wasmtime_pooling_allocation_config_t;

WASM_API_EXTERN wasmtime_pooling_allocation_config_t *
wasmtime_pooling_allocation_config_new();

WASM_API_EXTERN void wasmtime_pooling_allocation_config_delete(
wasmtime_pooling_allocation_config_t *);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add some documentation to these functions/types? Just some basic docs is fine, but for example indicating that *_new() must be deallocated with *_delete() and perhaps linking to the Rust documentation for wasmtime_pooling_allocation_config_t.

Also for wasmtime_pooling_allocation_strategy_set down below can you document that it doesn't take ownership of the pooling config and the pooling config still needs to be manually deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@fridaymore fridaymore requested a review from alexcrichton March 31, 2025 16:30
@alexcrichton alexcrichton added this pull request to the merge queue Mar 31, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 31, 2025
@alexcrichton alexcrichton enabled auto-merge March 31, 2025 18:01
@alexcrichton alexcrichton added this pull request to the merge queue Mar 31, 2025
Merged via the queue into bytecodealliance:main with commit ae69c92 Mar 31, 2025
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:c-api Issues pertaining to the C API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants