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

c#: Use Stack based return pointer for imports #1132

Merged

Conversation

jsturtevant
Copy link
Collaborator

@jsturtevant jsturtevant commented Jan 17, 2025

This updates the imports path to use a stack based return pointer similar to the way rust does it.

There are a few considerations:

  • the stack allocations are defined by the return payload so could potentially get larger than expected. Since its the programmer making this decision in the API I wasn't overly concerned. This could be mitigated by checking the size and allocating it on the heap as we are today
  • we have to do a slight over allocation with the c# stackalloc function since there is no way to control the alignment

I ran some iterations around the larger VariantCasts variant import test case and saw a slight speed difference (mostly negligible) and a ~13-15% reduction in memory usage:

# stack based
Average Time: 6.686999999999999 µs
Average Memory: 35463.2 bytes
Average Allocated Bytes: 31085.48 bytes

# heap based 
Average Time: 6.752000000000001 µs
Average Memory: 41055.52 bytes
Average Allocated Bytes: 36881.76 bytes

Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
@jsturtevant jsturtevant force-pushed the stackbased-return-for-imports branch from b0b6b41 to ecb056a Compare January 17, 2025 22:30
@alexcrichton alexcrichton added this pull request to the merge queue Jan 17, 2025
Merged via the queue into bytecodealliance:main with commit 94ba156 Jan 17, 2025
25 checks passed
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