Skip to content

Potential optimization for imported async functions #434

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

Open
cpetig opened this issue Jan 7, 2025 · 2 comments
Open

Potential optimization for imported async functions #434

cpetig opened this issue Jan 7, 2025 · 2 comments

Comments

@cpetig
Copy link

cpetig commented Jan 7, 2025

Exported async functions have been changed in November to receive their arguments on the value stack, so these function calls now impose less overhead.

Imported async functions on the other hand still use a heap allocated list to pass arguments. While this is motivated by minimal overhead for back-pressure it penalizes the common case of async function calls with few parameters, e.g. a string or list. The overhead to store the arguments on the host in the (less likely?) back-pressure case could be acceptable in comparison to this unconditional heap allocation on the client side.

When I brought this up in bytecodealliance/wit-bindgen#1082 (comment) Joel proposed to open discussion here.

@lukewagner
Copy link
Member

(Sorry for the slow reply; getting back from holidays) Currently, if there is only one flattened parameter, it is passed as a scalar instead of going through linear memory (see flatten_functype). So, one option we have is to relax increase this max-async-flat-parameters limit from 1 to something a bit bigger.

We do have to be a little careful since increasing this limit will increase the static size of the engine-internal structure used to represent async calls to have space for the maximum number of async flattened parameters. But maybe a modest increase to, say, "4" would be reasonable? It'd be nice to have performance data to motivate this, though.

@lukewagner
Copy link
Member

Proposed in #520.

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