Stream: git-wasmtime

Topic: wasmtime / PR #15145 Elide redundant typecheck when lower...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 16:16):

adamrk removed the review request for wasmtime-core-reviewers from PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 16:16):

adamrk opened PR #15145 from adamrk:abk/elide-reader-typecheck-followup to bytecodealliance:main:

When a StreamReader<T> or FutureReader<T> is lowered into a guest, typecheck_lowered_transmit checks the transmit's origin against the destination payload type. The type T has already been checked against the payload type, so this change allows the dynamic check to be elided in the cases when we can rely on the static check that was already done.

There are 3 cases to consider:

  1. A StreamReader<T> was directly created in the host by a Producer with P::Item == T. This case is marked with a bool tag in the HostResourceIndex and no further checks are needed.

  2. A StreamReader<T> was created by the host, but has been passed through a guest and may have had its type loosened (e.g. a StreamReader<StreamReader<String>> became a StreamReader<StreamAny>). In this case, we compare the TypeId of the Producer's P::Item against T and skip further checks if they match. If they don't match we dynamically run the Producer's typecheck.

  3. A StreamAny always runs the dynamic typecheck.

This shows a ~5% improvement in the p3_http_proxy benchmark:

Main (8c11e2e0edbd344886b6daab87aba5eb3a6e5ca9):

wasi-http/p3_http_proxy time:   [17.731 µs 17.751 µs 17.780 µs]
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) high mild
  4 (4.00%) high severe

wasi-http/p3-api/request.new
                        time:   [1.4515 µs 1.4536 µs 1.4561 µs]
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe

wasi-http/p3-api/response.consume-body
                        time:   [2.1158 µs 2.1311 µs 2.1449 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

wasi-http/p3-api/client.send
                        time:   [2.9556 µs 2.9614 µs 2.9667 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

Branch:

wasi-http/p3_http_proxy time:   [16.834 µs 16.858 µs 16.890 µs]
                        change: [−5.2232% −5.0299% −4.8189%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) high mild
  4 (4.00%) high severe

wasi-http/p3-api/request.new
                        time:   [1.1689 µs 1.1733 µs 1.1805 µs]
                        change: [−19.787% −19.146% −18.210%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
  2 (2.00%) low mild
  4 (4.00%) high mild
  2 (2.00%) high severe

wasi-http/p3-api/response.consume-body
                        time:   [1.7009 µs 1.7146 µs 1.7300 µs]
                        change: [−19.751% −18.733% −17.645%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

wasi-http/p3-api/client.send
                        time:   [2.9678 µs 2.9714 µs 2.9746 µs]
                        change: [+0.1770% +0.5625% +0.9582%] (p = 0.01 < 0.05)
                        Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.md

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 16:16):

adamrk requested cfallin for a review on PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 16:16):

adamrk requested wasmtime-core-reviewers for a review on PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 16:22):

:speech_balloon: adamrk created PR review comment:

Note: I'm a bit worried that sticking this tag in the HostResourceIndex could cause problems later since we don't have anything in the type system indicating that the tags exist. It seems to be worth about 1.5% of the overall 5% improvement in the http proxy benchmark, so I'm not really sure if it's worth it. I also tried just using a separate bool, but that seems to be a wash overall.

So I think we could remove the take and loose the fastest Elided path altogether, or maybe if we think index tagging could be useful in general it might make sense to introduce it into the types and use it here.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 16:22):

:memo: adamrk submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 18:44):

github-actions[bot] added the label wasmtime:api on PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 19:41):

adamrk updated PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 20:35):

alexcrichton removed the review request for cfallin from PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 20:35):

alexcrichton requested alexcrichton for a review on PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 20:58):

:memo: alexcrichton submitted PR review:

This seems reasonable to me yeah, but I'm curious if we can remove one of the variants of TransmitCheck if it's not needed for performance.

Otherwise though I think it'd be good to have some docs somewhere explaining the situation a bit more as well. Maybe on fn transmit_check or maybe on fn run, I'm not sure which. The general idea though is that T::typecheck has already run at some point and the second-layer of checking here is basically "is there more needed than that". I'm getting lost myself a bit in this, so I'm not entirely sure what such a comment would say though. For example lowering StreamReader<StreamAny> to a guest doesn't type-check further than stream<stream<?>> in the typecheck implementation up-front, but then sending a StreamAny on that stream does indeed type-check the ?.

I guess maybe I'm just a bit lost. Can you describe a bit more the situations where this is applying? For example what I can see is that if you create StreamReader<u8> then this is skipping a typecheck against InterfaceType::U8 which, while fast in theory, still involves some lookups and dynamic dispatch. I don't fully understand the Static vs Elided distinction though...

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 20:58):

:speech_balloon: alexcrichton created PR review comment:

For the benchmarks that you're looking at, is this case needed? I feel like this PR would be simpler without this, but if it's needed for performance then it's needed

view this post on Zulip Wasmtime GitHub notifications bot (Nov 04 2026 at 20:58):

:speech_balloon: alexcrichton created PR review comment:

Personally I'd lean towards an auxiliary bool rather than a tag bit given the usage of this index for other purposes too

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 20:49):

adamrk updated PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 20:49):

adamrk commented on PR #15145:

Sorry, I got distracted by some other stuff and took a while to get back to this. I've reworked it to just have the auxiliary boolean and I've added comments to clarify the invariant and why we can skip the typecheck when lowering the read end of a future/stream when the boolean is set.

Here are the benchmark numbers for the latest version:

Main (68f6475eac03b53a863c3e9c83ec587265fc70a4)

wasi-http/p3_http_proxy time:   [18.869 µs 18.887 µs 18.916 µs]
Found 7 outliers among 100 measurements (7.00%)
  2 (2.00%) high mild
  5 (5.00%) high severe

wasi-http/p3-api/request.new
                        time:   [1.6562 µs 1.6658 µs 1.6826 µs]
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild
  2 (2.00%) high severe

wasi-http/p3-api/response.consume-body
                        time:   [2.4195 µs 2.4584 µs 2.5194 µs]
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high severe

wasi-http/p3-api/client.send
                        time:   [3.0056 µs 3.0090 µs 3.0123 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

Branch

wasi-http/p3_http_proxy time:   [17.774 µs 17.796 µs 17.829 µs]
                        change: [−5.9549% −5.6885% −5.3230%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
  4 (4.00%) high mild
  4 (4.00%) high severe

wasi-http/p3-api/request.new
                        time:   [1.3877 µs 1.4049 µs 1.4269 µs]
                        change: [−16.860% −16.201% −15.506%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild
  4 (4.00%) high severe

wasi-http/p3-api/response.consume-body
                        time:   [2.0159 µs 2.0631 µs 2.1249 µs]
                        change: [−18.473% −17.073% −15.637%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high severe

wasi-http/p3-api/client.send
                        time:   [2.9696 µs 2.9743 µs 2.9792 µs]
                        change: [−1.3104% −1.0455% −0.7862%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 6 outliers among 100 measurements (6.00%)
  5 (5.00%) high mild
  1 (1.00%) high severe

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 20:50):

adamrk requested alexcrichton for a review on PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 22:21):

:thumbs_up: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 22:21):

alexcrichton added PR #15145 Elide redundant typecheck when lowering readers to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 22:45):

:check: alexcrichton merged PR #15145.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 22:45):

alexcrichton removed PR #15145 Elide redundant typecheck when lowering readers from the merge queue.


Last updated: Nov 19 2026 at 20:05 UTC