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

[Merged by Bors] - Use opcode table rather than match #2501

Closed
wants to merge 4 commits into from

Conversation

tunz
Copy link
Contributor

@tunz tunz commented Dec 21, 2022

execute_instruction is heavily used. After decoding an opcode, match is used to find a proper execute function for the opcode. But, the match may not be able to be optimized into a table jump by rust compiler, so it may use multiple branches to find the function. When I tested with a toy program, only enum -> &'static str case was optimized to use a table while enum -> function call uses multiple branches. (gotbolt)

This change makes the opcode to use a table explicitly. It improves the benchmark score of Richards by 1-2% (22.8 -> 23.2).

@codecov
Copy link

codecov bot commented Dec 21, 2022

Codecov Report

Merging #2501 (171edd7) into main (3bf5de2) will increase coverage by 0.16%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##             main    #2501      +/-   ##
==========================================
+ Coverage   51.43%   51.59%   +0.16%     
==========================================
  Files         354      354              
  Lines       35767    35641     -126     
==========================================
- Hits        18395    18390       -5     
+ Misses      17372    17251     -121     
Impacted Files Coverage Δ
boa_engine/src/vm/opcode/mod.rs 70.00% <66.66%> (+9.13%) ⬆️
boa_cli/src/main.rs 0.00% <0.00%> (-1.08%) ⬇️
boa_gc/src/cell.rs 63.84% <0.00%> (-0.57%) ⬇️
boa_engine/src/builtins/array/mod.rs 74.50% <0.00%> (-0.29%) ⬇️
boa_cli/src/helper.rs 0.00% <0.00%> (ø)
boa_examples/src/bin/symbol_visitor.rs 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jedel1043 jedel1043 added performance Performance related changes and issues execution Issues or PRs related to code execution vm Issues and PRs related to the Boa Virtual Machine. run-benchmark Label used to run banchmarks on PRs labels Dec 21, 2022
@jedel1043 jedel1043 added this to the v0.17.0 milestone Dec 21, 2022
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I have some suggestions to improve maintainability and performance.

boa_engine/src/vm/opcode/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/vm/opcode/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@jedel1043 jedel1043 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! I have just a simple nitpick, but gonna mark this as approved already😁

boa_engine/src/vm/opcode/mod.rs Outdated Show resolved Hide resolved
@jasonwilliams
Copy link
Member

This is awesome @tunz thanks, will take a look when I have time or in the new year

@jedel1043
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Dec 26, 2022
`execute_instruction` is heavily used. After decoding an opcode, `match` is used to find a proper `execute` function for the opcode. But, the `match` may not be able to be optimized into a table jump by rust compiler, so it may use multiple branches to find the function. When I tested with a toy program, only `enum -> &'static str` case was optimized to use a table while `enum -> function call` uses multiple branches. ([gotbolt](https://rust.godbolt.org/z/1rzK5vj6f))

This change makes the opcode to use a table explicitly. It improves the benchmark score of Richards by 1-2% (22.8 -> 23.2).
@bors
Copy link

bors bot commented Dec 26, 2022

Build failed:

@jedel1043
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Dec 26, 2022
`execute_instruction` is heavily used. After decoding an opcode, `match` is used to find a proper `execute` function for the opcode. But, the `match` may not be able to be optimized into a table jump by rust compiler, so it may use multiple branches to find the function. When I tested with a toy program, only `enum -> &'static str` case was optimized to use a table while `enum -> function call` uses multiple branches. ([gotbolt](https://rust.godbolt.org/z/1rzK5vj6f))

This change makes the opcode to use a table explicitly. It improves the benchmark score of Richards by 1-2% (22.8 -> 23.2).
@bors
Copy link

bors bot commented Dec 26, 2022

Build failed:

After decoding an opcode, `match` is used to find a proper `execute`
function for the opcode. But, the `match` may not be able to be
optimized into a linear table jump by rust compiler, so it may use
multiple branches to find the function.

This change makes the opcode to use a table explicitly. This change
improves the benchmark score of Richards about 1-2% (22.8 -> 23.2).
@jedel1043
Copy link
Member

Rebased to see if that's what's causing the fail

@jedel1043
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Dec 26, 2022
`execute_instruction` is heavily used. After decoding an opcode, `match` is used to find a proper `execute` function for the opcode. But, the `match` may not be able to be optimized into a table jump by rust compiler, so it may use multiple branches to find the function. When I tested with a toy program, only `enum -> &'static str` case was optimized to use a table while `enum -> function call` uses multiple branches. ([gotbolt](https://rust.godbolt.org/z/1rzK5vj6f))

This change makes the opcode to use a table explicitly. It improves the benchmark score of Richards by 1-2% (22.8 -> 23.2).
@bors
Copy link

bors bot commented Dec 26, 2022

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Use opcode table rather than match [Merged by Bors] - Use opcode table rather than match Dec 26, 2022
@bors bors bot closed this Dec 26, 2022
@tunz tunz deleted the tunz/opt-execute-instruction branch July 18, 2023 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
execution Issues or PRs related to code execution performance Performance related changes and issues run-benchmark Label used to run banchmarks on PRs vm Issues and PRs related to the Boa Virtual Machine.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants