Skip to content

[wasm] [jiterp] Add optimized C version of STFLD_O that uses correct write barrier#81806

Merged
kg merged 1 commit intodotnet:mainfrom
kg:wasm-jiterpreter-stfld_o
Feb 8, 2023
Merged

[wasm] [jiterp] Add optimized C version of STFLD_O that uses correct write barrier#81806
kg merged 1 commit intodotnet:mainfrom
kg:wasm-jiterpreter-stfld_o

Conversation

@kg
Copy link
Member

@kg kg commented Feb 8, 2023

This PR moves most of the jiterpreter's STFLD_O implementation into a C function that is responsible for also doing the null check. As a bonus that function is able to use the correct kind of write barrier (though it's not clear to me whether the previous one was broken in any way).

Local tests suggest that this speeds up the LinkedList version of CreateAddAndClear, one of the regressions in dotnet/perf-autofiling-issues#12762. The heavy pointer chasing and null checks in LinkedList<T>.InternalInsertNodeBefore seem likely to be causing branch predictor/cache strain since in the interpreter it's the same null check passing every time (predicts accurately with no issues and won't fall out of cache) while in the jiterpreter we now have a compiled trace with a bunch of unique null checks in it.

In the future I hope to apply some other optimizations to null checks that should improve this further and improve other cases, but STFLD_O is the worst case due to the need to pass computed addresses to the write barrier.

@kg kg added the arch-wasm WebAssembly architecture label Feb 8, 2023
@ghost ghost assigned kg Feb 8, 2023
@ghost
Copy link

ghost commented Feb 8, 2023

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

This PR moves most of the jiterpreter's STFLD_O implementation into a C function that is responsible for also doing the null check. As a bonus that function is able to use the correct kind of write barrier (though it's not clear to me whether the previous one was broken in any way).

Local tests suggest that this speeds up the LinkedList version of CreateAddAndClear, one of the regressions in dotnet/perf-autofiling-issues#12762. The heavy pointer chasing and null checks in LinkedList<T>.InternalInsertNodeBefore seem likely to be causing branch predictor/cache strain since in the interpreter it's the same null check passing every time (predicts accurately with no issues and won't fall out of cache) while in the jiterpreter we now have a compiled trace with a bunch of unique null checks in it.

In the future I hope to apply some other optimizations to null checks that should improve this further and improve other cases, but STFLD_O is the worst case due to the need to pass computed addresses to the write barrier.

Author: kg
Assignees: -
Labels:

arch-wasm

Milestone: -

@ghost
Copy link

ghost commented Feb 8, 2023

Tagging subscribers to this area: @BrzVlad, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

Issue Details

This PR moves most of the jiterpreter's STFLD_O implementation into a C function that is responsible for also doing the null check. As a bonus that function is able to use the correct kind of write barrier (though it's not clear to me whether the previous one was broken in any way).

Local tests suggest that this speeds up the LinkedList version of CreateAddAndClear, one of the regressions in dotnet/perf-autofiling-issues#12762. The heavy pointer chasing and null checks in LinkedList<T>.InternalInsertNodeBefore seem likely to be causing branch predictor/cache strain since in the interpreter it's the same null check passing every time (predicts accurately with no issues and won't fall out of cache) while in the jiterpreter we now have a compiled trace with a bunch of unique null checks in it.

In the future I hope to apply some other optimizations to null checks that should improve this further and improve other cases, but STFLD_O is the worst case due to the need to pass computed addresses to the write barrier.

Author: kg
Assignees: kg
Labels:

arch-wasm, area-Codegen-Interpreter-mono

Milestone: -

@kg kg marked this pull request as ready for review February 8, 2023 03:18
@kg kg merged commit 8f3a34d into dotnet:main Feb 8, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants