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] - Split vm/opcode into modules #2343

Closed
wants to merge 12 commits into from

Conversation

nekevss
Copy link
Member

@nekevss nekevss commented Oct 14, 2022

Hi!

This isn't really related to a pull request that I know of. I was trying to better wrap my head around Boa's VM and thought I'd break it apart so that the file wasn't 2500+ lines. I figured I'd submit it as a draft and get feedback/see if anyone was interested in it. The way the modules were broken apart was primarily based off the opcode name (GetFunction & GetFunctionAsync -> ./get/function.rs).

It changes the following:

  • Adds an Operation trait to opcode/mod.rs
  • Implements Operation for each Opcode variant, moving the executable instruction code from vm/mod.rs to the respective module

@codecov
Copy link

codecov bot commented Oct 14, 2022

Codecov Report

Merging #2343 (5698bde) into main (dc9c1cb) will increase coverage by 0.24%.
The diff coverage is 45.74%.

@@            Coverage Diff             @@
##             main    #2343      +/-   ##
==========================================
+ Coverage   39.84%   40.09%   +0.24%     
==========================================
  Files         242      304      +62     
  Lines       23242    23369     +127     
==========================================
+ Hits         9260     9369     +109     
- Misses      13982    14000      +18     
Impacted Files Coverage Δ
boa_engine/src/vm/mod.rs 57.39% <ø> (+13.52%) ⬆️
boa_engine/src/vm/opcode/await_stm/mod.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/define/class/getter.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/define/class/method.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/define/class/setter.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/generator/mod.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/generator/yield_stm.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/get/generator.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/get/private.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/iteration/for_await.rs 0.00% <0.00%> (ø)
... and 89 more

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

@Razican Razican added enhancement New feature or request technical debt vm Issues and PRs related to the Boa Virtual Machine. Internal Category for changelog labels Oct 14, 2022
@Razican Razican added this to the v0.17.0 milestone Oct 14, 2022
@Razican
Copy link
Member

Razican commented Oct 14, 2022

Great work!! Thank you for this contribution :)

This is related to #1808, but for the VM instead of the byte compiler, if I'm not mistaken.

@nekevss nekevss marked this pull request as ready for review October 14, 2022 14:08
@jasonwilliams jasonwilliams linked an issue Oct 15, 2022 that may be closed by this pull request
@nekevss
Copy link
Member Author

nekevss commented Oct 21, 2022

Just wanted to follow up that this is probably ready for review (updated to some of the recent pull requests). 😄

@Razican
Copy link
Member

Razican commented Oct 21, 2022

Test262 conformance changes

VM implementation

Test result main count PR count difference
Total 93,383 93,383 0
Passed 69,095 69,095 0
Ignored 18,182 18,182 0
Failed 6,106 6,106 0
Panics 0 0 0
Conformance 73.99% 73.99% 0.00%

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

Great work!! This is very helpful.

I added a couple of comments. I like the approach, and I would be OK to merge it as-is, but check if my comments make sense. Also, this is missing documentation of all the op-codes, but we didn't have such documentation before, so, if you add it, that would be great, but if not, I'm OK to merge it as-is and create an issue to do it later :)

boa_engine/src/vm/opcode/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/vm/opcode/mod.rs Show resolved Hide resolved
@Razican Razican removed a link to an issue Oct 21, 2022
Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me :)

@raskad raskad added the run-benchmark Label used to run banchmarks on PRs label Oct 22, 2022
@raskad
Copy link
Member

raskad commented Oct 22, 2022

I like the change. I pushed an empty commit to trigger the benchmarks to see if there is any noticeable change in how the code is compiled/optimized.

Copy link
Member

@HalidOdat HalidOdat 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 to me :)

@Razican
Copy link
Member

Razican commented Oct 22, 2022

Too much standard deviation, difficult to say, but I don't see it went worse, and we might even have some gains.

┌─────────┬──────────────────────────────────────────────┬───────────────────────┬───────────────────────┬────────────┐
│ (index) │                     name                     │     baseDuration      │    changesDuration    │ difference │
├─────────┼──────────────────────────────────────────────┼───────────────────────┼───────────────────────┼────────────┤
│    0    │      'Arithmetic operations (Compiler)'      │    '666.2±47.77ns'    │    '667.7±58.22ns'    │   '0.0'    │
│    1    │     'Arithmetic operations (Execution)'      │    '689.4±72.20ns'    │  '**584.2±48.15ns**'  │   '-15'    │
│    2    │       'Arithmetic operations (Parser)'       │   '**6.9±0.45µs**'    │     '7.4±0.53µs'      │   '+7.0'   │
│    3    │          'Array access (Compiler)'           │   '1792.3±95.59ns'    │ '**1778.5±140.42ns**' │  '-0.99'   │
│    4    │          'Array access (Execution)'          │   '**10.8±0.82µs**'   │     '11.2±0.87µs'     │   '+3.0'   │
│    5    │           'Array access (Parser)'            │     '15.0±0.91µs'     │   '**14.8±1.00µs**'   │  '-0.99'   │
│    6    │         'Array creation (Compiler)'          │   '**2.7±0.18µs**'    │     '2.8±0.27µs'      │   '+4.0'   │
│    7    │         'Array creation (Execution)'         │   '1453.8±104.58µs'   │ '**1434.1±101.41µs**' │  '-0.99'   │
│    8    │          'Array creation (Parser)'           │     '19.0±2.55µs'     │   '**18.5±1.56µs**'   │   '-2.9'   │
│    9    │            'Array pop (Compiler)'            │   '**4.6±0.27µs**'    │     '4.9±0.45µs'      │   '+5.0'   │
│   10    │           'Array pop (Execution)'            │  '**866.5±88.80µs**'  │    '872.0±86.13µs'    │   '+1.0'   │
│   11    │             'Array pop (Parser)'             │  '**163.8±10.15µs**'  │    '165.0±8.84µs'     │   '+1.0'   │
│   12    │      'Boolean Object Access (Compiler)'      │ '**1367.0±272.73ns**' │   '1397.8±162.75ns'   │   '+2.0'   │
│   13    │     'Boolean Object Access (Execution)'      │   '**6.5±0.55µs**'    │     '6.6±0.78µs'      │   '+2.0'   │
│   14    │       'Boolean Object Access (Parser)'       │     '17.6±1.46µs'     │   '**17.2±0.97µs**'   │   '-2.9'   │
│   15    │            'Clean js (Compiler)'             │     '6.0±0.33µs'      │     '5.9±0.53µs'      │   '0.0'    │
│   16    │            'Clean js (Execution)'            │    '866.6±53.33µs'    │  '**850.6±53.68µs**'  │   '-2.0'   │
│   17    │             'Clean js (Parser)'              │   '**37.1±3.29µs**'   │     '38.8±5.45µs'     │   '+4.0'   │
│   18    │                'Create Realm'                │  '**284.0±14.95ns**'  │    '312.6±25.01ns'    │   '+10'    │
│   19    │ 'Dynamic Object Property Access (Compiler)'  │     '2.1±0.11µs'      │     '2.1±0.11µs'      │   '0.0'    │
│   20    │ 'Dynamic Object Property Access (Execution)' │     '7.0±0.82µs'      │   '**6.6±0.64µs**'    │   '-4.8'   │
│   21    │  'Dynamic Object Property Access (Parser)'   │     '13.8±1.09µs'     │     '13.8±1.41µs'     │   '0.0'    │
│   22    │            'Fibonacci (Compiler)'            │   '**3.3±0.32µs**'    │     '3.3±0.24µs'      │   '+3.0'   │
│   23    │           'Fibonacci (Execution)'            │ '**1374.5±138.62µs**' │   '1419.7±93.57µs'    │   '+3.0'   │
│   24    │             'Fibonacci (Parser)'             │     '21.1±1.38µs'     │   '**20.7±1.94µs**'   │   '-2.0'   │
│   25    │            'For loop (Compiler)'             │   '**3.2±0.31µs**'    │     '3.3±0.43µs'      │   '+6.0'   │
│   26    │            'For loop (Execution)'            │   '**20.7±1.94µs**'   │     '21.0±1.74µs'     │   '+1.0'   │
│   27    │             'For loop (Parser)'              │     '18.3±1.12µs'     │   '**18.2±0.95µs**'   │  '-0.99'   │
│   28    │             'Mini js (Compiler)'             │   '**5.1±0.47µs**'    │     '5.7±0.92µs'      │   '+13'    │
│   29    │            'Mini js (Execution)'             │    '780.6±45.59µs'    │  '**770.4±44.45µs**'  │  '-0.99'   │
│   30    │              'Mini js (Parser)'              │   '**32.1±1.53µs**'   │     '32.4±3.78µs'     │   '+1.0'   │
│   31    │      'Number Object Access (Compiler)'       │ '**1273.5±394.98ns**' │   '1292.6±115.16ns'   │   '+2.0'   │
│   32    │      'Number Object Access (Execution)'      │     '5.2±0.36µs'      │   '**5.1±0.45µs**'    │   '-2.0'   │
│   33    │       'Number Object Access (Parser)'        │   '**14.0±2.28µs**'   │     '14.1±1.50µs'     │   '+1.0'   │
│   34    │         'Object Creation (Compiler)'         │ '**1908.4±189.70ns**' │     '2.0±0.29µs'      │   '+7.0'   │
│   35    │        'Object Creation (Execution)'         │   '**6.2±0.47µs**'    │     '6.3±0.39µs'      │   '+2.0'   │
│   36    │          'Object Creation (Parser)'          │   '**12.0±0.96µs**'   │     '12.2±0.93µs'     │   '+1.0'   │
│   37    │             'RegExp (Compiler)'              │     '2.1±0.17µs'      │     '2.1±0.16µs'      │   '0.0'    │
│   38    │             'RegExp (Execution)'             │   '**17.1±1.87µs**'   │     '18.8±9.02µs'     │   '+10'    │
│   39    │              'RegExp (Parser)'               │     '13.1±1.39µs'     │   '**12.9±0.88µs**'   │  '-0.99'   │
│   40    │         'RegExp Creation (Compiler)'         │ '**1974.3±163.36ns**' │     '2.0±0.34µs'      │   '+3.0'   │
│   41    │        'RegExp Creation (Execution)'         │     '11.9±2.11µs'     │   '**11.6±0.74µs**'   │   '-2.9'   │
│   42    │          'RegExp Creation (Parser)'          │   '**10.9±0.47µs**'   │     '10.9±1.03µs'     │   '+1.0'   │
│   43    │         'RegExp Literal (Compiler)'          │     '2.1±0.12µs'      │     '2.1±0.14µs'      │   '0.0'    │
│   44    │         'RegExp Literal (Execution)'         │   '**16.9±1.10µs**'   │     '17.7±1.59µs'     │   '+5.0'   │
│   45    │          'RegExp Literal (Parser)'           │     '10.4±0.50µs'     │   '**10.3±0.54µs**'   │  '-0.99'   │
│   46    │     'RegExp Literal Creation (Compiler)'     │ '**1910.2±96.31ns**'  │   '1956.3±117.89ns'   │   '+2.0'   │
│   47    │    'RegExp Literal Creation (Execution)'     │     '11.6±0.94µs'     │     '11.6±0.78µs'     │   '0.0'    │
│   48    │      'RegExp Literal Creation (Parser)'      │     '8.1±0.30µs'      │   '**8.1±0.63µs**'    │  '-0.99'   │
│   49    │  'Static Object Property Access (Compiler)'  │ '**1915.7±153.87ns**' │   '1935.9±127.46ns'   │   '+1.0'   │
│   50    │ 'Static Object Property Access (Execution)'  │     '6.7±0.76µs'      │   '**6.2±0.35µs**'    │   '-8.3'   │
│   51    │   'Static Object Property Access (Parser)'   │   '**12.8±0.72µs**'   │     '12.8±1.50µs'     │   '+1.0'   │
│   52    │      'String Object Access (Compiler)'       │ '**1699.2±105.07ns**' │   '1740.0±139.72ns'   │   '+2.0'   │
│   53    │      'String Object Access (Execution)'      │     '9.3±1.09µs'      │   '**9.1±0.90µs**'    │   '-2.0'   │
│   54    │       'String Object Access (Parser)'        │   '**16.8±1.62µs**'   │     '18.0±1.50µs'     │   '+7.0'   │
│   55    │        'String comparison (Compiler)'        │   '**2.7±0.13µs**'    │     '2.8±0.18µs'      │   '+1.0'   │
│   56    │       'String comparison (Execution)'        │     '5.5±0.53µs'      │   '**5.4±0.31µs**'    │  '-0.99'   │
│   57    │         'String comparison (Parser)'         │     '14.6±3.45µs'     │   '**14.4±2.06µs**'   │  '-0.99'   │
│   58    │      'String concatenation (Compiler)'       │   '**2.2±0.17µs**'    │     '2.2±0.21µs'      │   '+1.0'   │
│   59    │      'String concatenation (Execution)'      │   '**5.0±0.41µs**'    │     '5.2±0.52µs'      │   '+3.0'   │
│   60    │       'String concatenation (Parser)'        │     '10.0±0.98µs'     │   '**9.7±0.55µs**'    │   '-2.0'   │
│   61    │           'String copy (Compiler)'           │ '**1769.8±99.02ns**'  │   '1800.9±114.46ns'   │   '+2.0'   │
│   62    │          'String copy (Execution)'           │     '5.0±0.61µs'      │   '**4.9±0.29µs**'    │   '-2.0'   │
│   63    │            'String copy (Parser)'            │   '**7.4±0.54µs**'    │     '7.5±0.71µs'      │   '+1.0'   │
│   64    │             'Symbols (Compiler)'             │   '1375.1±138.63ns'   │ '**1366.5±121.95ns**' │  '-0.99'   │
│   65    │            'Symbols (Execution)'             │     '5.3±0.62µs'      │   '**4.9±0.34µs**'    │   '-7.4'   │
│   66    │              'Symbols (Parser)'              │     '5.9±0.60µs'      │     '5.9±0.45µs'      │   '0.0'    │
│   67    │                      ''                      │       undefined       │       undefined       │   '+NaN'   │
└─────────┴──────────────────────────────────────────────┴───────────────────────┴───────────────────────┴────────────┘

@raskad
Copy link
Member

raskad commented Oct 22, 2022

bors r+

bors bot pushed a commit that referenced this pull request Oct 22, 2022
<!---
Thank you for contributing to Boa! Please fill out the template below, and remove or add any
information as you feel necessary.
--->
Hi!

This isn't really related to a pull request that I know of. I was trying to better wrap my head around Boa's VM and thought I'd break it apart so that the file wasn't 2500+ lines. I figured I'd submit it as a draft and get feedback/see if anyone was interested in it. The way the modules were broken apart was primarily based off the opcode name (`GetFunction` & `GetFunctionAsync` -> `./get/function.rs`).

It changes the following:

- Adds an `Operation` trait to opcode/mod.rs
- Implements `Operation` for each Opcode variant, moving the executable instruction code from `vm/mod.rs` to the respective module



Co-authored-by: raskad <32105367+raskad@users.noreply.github.com>
@bors
Copy link

bors bot commented Oct 22, 2022

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Split vm/opcode into modules [Merged by Bors] - Split vm/opcode into modules Oct 22, 2022
@bors bors bot closed this Oct 22, 2022
@Razican Razican added the hacktoberfest-accepted PR accepted for Hacktoberfest label Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest-accepted PR accepted for Hacktoberfest Internal Category for changelog run-benchmark Label used to run banchmarks on PRs technical debt vm Issues and PRs related to the Boa Virtual Machine.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants