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

Reduced allocations #202

Merged

Conversation

martindevans
Copy link
Contributor

@martindevans martindevans commented Dec 13, 2022

  • Using Array.Empty where possible
  • Get UTF8 bytes into a Memory<byte> rented from the shared memory pool instead of a byte[]
  • Replaced some LINQ with a for loop
  • Modified some private helper functions to return more appropriate types based on their ultimate uses
  • Removed TypeHandle used in Memory - it was only used in two places with trivial lifetimes.

@martindevans martindevans changed the title Reduced allocations in Linker.DefineFunction Reduced allocations Dec 14, 2022
src/Function.FromCallback.tt Outdated Show resolved Hide resolved
@martindevans
Copy link
Contributor Author

CI failure due to an issue downloading a dependency:

Response status code does not indicate success: 503 (Egress is over the account limit.).

martindevans and others added 9 commits January 24, 2023 14:01
 - Using `Array.Empty` where possible
 - Get UTF8 bytes into a stackalloc `Span<byte>` instead of a `byte[]`
…is prevents stack overflows with very long strings.
…ypes`

 - Returning `null` instead of a single item array which is never used in `GetTupleTypes`
 - Return a list from `GetTupleTypes` instead of an array which is always immediately converted to a list
 - Using `Array.Empty` in `Function.Wrap` where possible
 - Removed `NullParams` (never used)
Co-authored-by: Konstantin Preißer <kpreisser@users.noreply.github.com>
…ine. It was only used in two places with trivial lifetimes.
@martindevans martindevans force-pushed the linker_reduces_allocations branch from 9c95a63 to 853957a Compare January 24, 2023 14:09
@martindevans
Copy link
Contributor Author

Rebased onto master to fixed merge conflict.

@peterhuene peterhuene self-requested a review January 24, 2023 20:06
Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

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

Looks good, just two formatting nits 👍

src/Export.cs Outdated Show resolved Hide resolved
src/Import.cs Outdated Show resolved Hide resolved
martindevans and others added 2 commits January 24, 2023 20:14
Co-authored-by: Peter Huene <peter@huene.dev>
Co-authored-by: Peter Huene <peter@huene.dev>
@martindevans
Copy link
Contributor Author

martindevans commented Jan 24, 2023

Committed those two suggestions. Thanks for the review 👍

@peterhuene peterhuene enabled auto-merge (squash) January 24, 2023 20:21
@peterhuene peterhuene merged commit 18020d2 into bytecodealliance:main Jan 24, 2023
kpreisser added a commit to kpreisser/wasmtime-dotnet that referenced this pull request Jan 24, 2023
…g overloads of Linker.DefineFunction, to reduce allocations for the strings.
peterhuene added a commit that referenced this pull request Jan 24, 2023
* Allow to specify functions using untyped callbacks, which allows to specify a callback of any type without the need to use a specific delegate type.

The untyped callback will receive arguments and can set results as a span of ValueBox.

For example, this allows to define trapping functions for a module's import without having to know the function time at compile-time, similar to Wasmtime's define_unknown_imports_as_traps.

* Follow-Up: Initialize the result ValueBoxes with their expected ValueKind but a default value, as otherwise they all would be initialized with ValueKind.Int32.

* Follow-Up: Pull the (int) cast up, to align with InvokeCallback().

* Fix wording.

* Enhance the tests to also check the ValueKind.

* Fix code style.

Co-authored-by: Peter Huene <peter@huene.dev>

* Add missing GC.KeepAlive() call (which corresponds to the changes from #206).

* Apply the changes from #202 also for the two remaining overloads of Linker.DefineFunction, to reduce allocations for the strings.

* Follow-Up: Adjust for the changes in #211.

Co-authored-by: Peter Huene <peter@huene.dev>
@martindevans martindevans deleted the linker_reduces_allocations branch July 2, 2024 10:23
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.

3 participants