Skip to content

Stop using stdio #99

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

Draft
wants to merge 11 commits into
base: jc.singleton-take2
Choose a base branch
from
Draft

Stop using stdio #99

wants to merge 11 commits into from

Conversation

jeffcharles
Copy link
Contributor

@jeffcharles jeffcharles commented Jun 23, 2025

Built on top of removing context pointer and using singleton context.

Replace stdio with initialization and finalization functions relying on reading from and writing to in-memory buffers from the host instead of using WASI hostcalls. This introduces a ~27% reduction in fuel (14,828 to 10,830) in one of the benchmark cases when excluding the initialization and finalization invocations from the fuel measurements compared to the numbers when introducing the singleton context. The reduction in fuel compared to main for that benchmark test is ~32% (15,880 to 10,830).

Copy link
Member

@saulecabrera saulecabrera left a comment

Choose a reason for hiding this comment

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

This is looking really good!

impl Default for Context {
fn default() -> Self {
Self {
bump_allocator: Bump::new(),
input_bytes: Vec::new(),
output_bytes: ByteBuf::new(),
logs: Vec::with_capacity(1024),
Copy link
Member

Choose a reason for hiding this comment

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

Given that we have now landed in explicit initialize / finalize function invocations, I wonder if we should make this configurable from the host?

Copy link
Member

@saulecabrera saulecabrera Jun 25, 2025

Choose a reason for hiding this comment

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

I think we briefly discussed that earlier on, maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can pass it as an additional parameter in initialize. But also, it's a vector so it'll grow beyond the initial capacity if it needs to. But using the default capacity definitely hurts performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I guess another tradeoff is if the initial capacity changes, then the fuel consumption for a Function that performs logging may change as well. If we reduce the initial capacity, then a Function that performs enough logging to exceed the new capacity that would not have exceeded the old capacity would see an increase in fuel consumption. And if the initial capacity were increased, then a Function that performed enough logging to exceed the old capacity but not enough to exceed the new capacity would see a decrease in fuel consumption.

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