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

Optimize integer negation #1464

Merged
merged 3 commits into from
Sep 10, 2021
Merged

Optimize integer negation #1464

merged 3 commits into from
Sep 10, 2021

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Aug 12, 2021

It changes the following:

  • Negation of integer now return integer.
  • Fix the % operator to return a number with the sign of its lhs.

@HalidOdat HalidOdat added performance Performance related changes and issues execution Issues or PRs related to code execution labels Aug 12, 2021
@HalidOdat HalidOdat added this to the v0.13.0 milestone Aug 12, 2021
@github-actions
Copy link

github-actions bot commented Aug 12, 2021

Test262 conformance changes:

Test result master count PR count difference
Total 80,685 80,685 0
Passed 32,988 32,988 0
Ignored 15,818 15,818 0
Failed 31,879 31,879 0
Panics 0 0 0
Conformance 40.88% 40.88% 0.00%

@HalidOdat HalidOdat force-pushed the optimization/integer-negation branch from 23e99eb to bdd3596 Compare August 12, 2021 00:27
@github-actions
Copy link

Benchmark for 49fecec

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 238.9±17.27ns 255.0±25.98ns -6.31%
Arithmetic operations (Full) 291.8±13.24µs 291.4±14.65µs +0.14%
Array access (Execution) 5.9±0.39µs 5.7±0.35µs +3.51%
Array access (Full) 296.9±21.08µs 299.5±17.13µs -0.87%
Array creation (Execution) 2.6±0.18ms 2.6±0.15ms 0.00%
Array creation (Full) 3.1±0.20ms 3.2±0.22ms -3.13%
Array pop (Execution) 897.2±50.05µs 875.5±50.21µs +2.48%
Array pop (Full) 1423.3±84.65µs 1384.0±80.83µs +2.84%
Boolean Object Access (Execution) 5.2±0.61µs 5.1±0.39µs +1.96%
Boolean Object Access (Full) 301.8±16.45µs 293.7±15.89µs +2.76%
Clean js (Execution) 705.0±52.38µs 728.6±35.76µs -3.24%
Clean js (Full) 1048.8±58.43µs 1021.6±66.62µs +2.66%
Clean js (Parser) 33.9±2.43µs 32.6±2.06µs +3.99%
Create Realm 402.4±42.76ns 392.8±24.36ns +2.44%
Dynamic Object Property Access (Execution) 5.0±0.39µs 4.7±0.31µs +6.38%
Dynamic Object Property Access (Full) 294.1±16.84µs 301.1±18.58µs -2.32%
Expression (Parser) 6.1±0.33µs 5.6±0.33µs +8.93%
Fibonacci (Execution) 763.6±38.76µs 786.0±42.07µs -2.85%
Fibonacci (Full) 1153.4±51.49µs 1096.9±64.06µs +5.15%
For loop (Execution) 18.8±1.25µs 19.1±1.08µs -1.57%
For loop (Full) 312.1±17.66µs 302.6±18.22µs +3.14%
For loop (Parser) 16.0±0.84µs 15.4±0.87µs +3.90%
Goal Symbols (Parser) 11.5±1.17µs 12.1±0.58µs -4.96%
Hello World (Parser) 3.6±0.63µs 3.2±0.27µs +12.50%
Long file (Parser) 734.1±41.81ns 759.6±35.71ns -3.36%
Mini js (Execution) 612.2±35.92µs 623.8±34.10µs -1.86%
Mini js (Full) 967.9±51.00µs 976.5±62.64µs -0.88%
Mini js (Parser) 28.3±2.37µs 27.1±1.67µs +4.43%
Number Object Access (Execution) 3.9±0.20µs 4.0±0.29µs -2.50%
Number Object Access (Full) 295.2±15.80µs 291.2±12.62µs +1.37%
Object Creation (Execution) 4.4±0.23µs 4.5±0.34µs -2.22%
Object Creation (Full) 312.6±16.99µs 305.5±21.99µs +2.32%
RegExp (Execution) 12.6±0.76µs 11.9±0.66µs +5.88%
RegExp (Full) 307.0±19.19µs 318.6±17.00µs -3.64%
RegExp Literal (Execution) 12.4±0.67µs 12.5±0.87µs -0.80%
RegExp Literal (Full) 316.3±18.58µs 314.7±31.60µs +0.51%
RegExp Literal Creation (Execution) 9.2±0.98µs 8.7±0.49µs +5.75%
RegExp Literal Creation (Full) 312.7±19.93µs 306.1±15.26µs +2.16%
Static Object Property Access (Execution) 4.5±0.26µs 4.3±0.25µs +4.65%
Static Object Property Access (Full) 295.6±29.49µs 293.2±19.00µs +0.82%
String Object Access (Execution) 6.6±0.49µs 6.9±0.44µs -4.35%
String Object Access (Full) 316.4±20.77µs 299.5±20.09µs +5.64%
String comparison (Execution) 6.0±0.56µs 6.1±0.32µs -1.64%
String comparison (Full) 311.8±14.22µs 315.3±18.56µs -1.11%
String concatenation (Execution) 4.7±0.32µs 4.7±0.32µs 0.00%
String concatenation (Full) 294.4±20.42µs 293.2±19.06µs +0.41%
String copy (Execution) 3.9±0.24µs 3.8±0.18µs +2.63%
String copy (Full) 286.9±21.33µs 293.9±17.97µs -2.38%
Symbols (Execution) 3.3±0.26µs 3.2±0.18µs +3.12%
Symbols (Full) 278.0±18.58µs 281.7±50.28µs -1.31%

@github-actions
Copy link

Benchmark for bc2c790

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 223.2±0.21ns 223.6±0.32ns -0.18%
Arithmetic operations (Full) 258.2±0.56µs 256.3±0.52µs +0.74%
Array access (Execution) 5.5±0.02µs 5.5±0.01µs 0.00%
Array access (Full) 280.2±1.66µs 278.9±0.43µs +0.47%
Array creation (Execution) 2.4±0.00ms 2.4±0.00ms 0.00%
Array creation (Full) 3.0±0.00ms 2.9±0.00ms +3.45%
Array pop (Execution) 789.8±4.03µs 787.2±3.63µs +0.33%
Array pop (Full) 1299.9±3.92µs 1265.1±3.33µs +2.75%
Boolean Object Access (Execution) 4.6±0.01µs 4.6±0.03µs 0.00%
Boolean Object Access (Full) 274.0±0.38µs 272.6±1.59µs +0.51%
Clean js (Execution) 614.4±3.23µs 617.4±3.77µs -0.49%
Clean js (Full) 935.9±3.17µs 928.6±3.32µs +0.79%
Clean js (Parser) 30.7±0.09µs 30.8±0.07µs -0.32%
Create Realm 357.5±0.30ns 354.2±0.16ns +0.93%
Dynamic Object Property Access (Execution) 4.3±0.01µs 4.3±0.01µs 0.00%
Dynamic Object Property Access (Full) 276.4±0.32µs 276.5±2.60µs -0.04%
Expression (Parser) 5.1±0.00µs 5.2±0.00µs -1.92%
Fibonacci (Execution) 672.9±0.57µs 673.4±0.55µs -0.07%
Fibonacci (Full) 980.2±1.12µs 980.0±0.78µs +0.02%
For loop (Execution) 17.0±0.21µs 16.8±0.04µs +1.19%
For loop (Full) 284.0±0.35µs 282.2±0.30µs +0.64%
For loop (Parser) 14.7±0.04µs 14.7±0.04µs 0.00%
Goal Symbols (Parser) 10.7±0.08µs 10.7±0.03µs 0.00%
Hello World (Parser) 3.0±0.02µs 3.0±0.01µs 0.00%
Long file (Parser) 743.7±18.85ns 745.7±18.92ns -0.27%
Mini js (Execution) 563.7±4.52µs 564.6±5.05µs -0.16%
Mini js (Full) 882.2±4.37µs 872.4±2.92µs +1.12%
Mini js (Parser) 27.2±0.04µs 27.1±0.09µs +0.37%
Number Object Access (Execution) 3.6±0.01µs 3.6±0.00µs 0.00%
Number Object Access (Full) 270.4±0.74µs 268.6±0.32µs +0.67%
Object Creation (Execution) 3.9±0.01µs 3.9±0.01µs 0.00%
Object Creation (Full) 272.7±0.63µs 272.0±3.07µs +0.26%
RegExp (Execution) 10.7±0.08µs 11.1±0.04µs -3.60%
RegExp (Full) 279.3±0.31µs 280.9±0.74µs -0.57%
RegExp Literal (Execution) 10.7±0.06µs 11.1±0.03µs -3.60%
RegExp Literal (Full) 286.0±0.72µs 285.2±0.71µs +0.28%
RegExp Literal Creation (Execution) 7.9±0.04µs 8.3±0.02µs -4.82%
RegExp Literal Creation (Full) 276.8±1.22µs 275.7±0.38µs +0.40%
Static Object Property Access (Execution) 4.0±0.01µs 4.1±0.03µs -2.44%
Static Object Property Access (Full) 276.6±0.23µs 273.4±0.39µs +1.17%
String Object Access (Execution) 6.1±0.08µs 6.1±0.02µs 0.00%
String Object Access (Full) 276.2±0.36µs 275.0±0.42µs +0.44%
String comparison (Execution) 5.4±0.02µs 5.5±0.03µs -1.82%
String comparison (Full) 278.1±0.59µs 273.8±0.27µs +1.57%
String concatenation (Execution) 4.3±0.01µs 4.3±0.02µs 0.00%
String concatenation (Full) 272.4±0.54µs 268.1±0.70µs +1.60%
String copy (Execution) 3.3±0.01µs 3.4±0.01µs -2.94%
String copy (Full) 265.8±0.44µs 264.4±0.85µs +0.53%
Symbols (Execution) 3.0±0.01µs 3.0±0.01µs 0.00%
Symbols (Full) 253.9±0.51µs 251.6±0.24µs +0.91%

@Razican
Copy link
Member

Razican commented Aug 18, 2021

Interestingly, it's failing 4 tests

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.

I extracted one of the checks in the failing test:

if (-1 % -1 !== -0) {
  $ERROR('#2.1: -1 % -1 === 0. Actual: ' + (-1 % -1));
} else {
  if (1 / (-1 % -1) !== Number.NEGATIVE_INFINITY) {
    $ERROR('#2.2: -1 % -1 === - 0. Actual: +0');
  }
}

EcmaScript requires that -1 % -1 must have the information of the sign in order to return f64::NEGATIVE_INFINITY in case we divide a number by -1 % -1.

With the changes on this commit, -1i32 % -1i32 returns 0i32, making 1 / (-1 % -1) === f64::POSITIVE_INFINITY. This fails the second check.

So, to pass this test we would need to change the rem operator to return a -0.0f64 if x < 0 in x % y === 0

Nonetheless, it's still necessary to convert -0 to f64 to pass the other test.

@HalidOdat
Copy link
Member Author

HalidOdat commented Aug 20, 2021

Yup. The integer module operation is not spec compliant, ill try to look into it this weekend

@jedel1043 jedel1043 force-pushed the optimization/integer-negation branch from bdd3596 to f14ac7e Compare September 9, 2021 20:37
@jedel1043 jedel1043 force-pushed the optimization/integer-negation branch from f14ac7e to 10dc64b Compare September 9, 2021 20:46
@jedel1043
Copy link
Member

Fixed the mod operator.

@jedel1043 jedel1043 merged commit 1348249 into master Sep 10, 2021
@jedel1043 jedel1043 deleted the optimization/integer-negation branch September 10, 2021 00:22
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants