Skip to content

Conversation

@kjarosh
Copy link
Member

@kjarosh kjarosh commented Oct 14, 2025

This is a performance optimization, as it gets rid of range checks when operating on values. Since we already implement value normalization, we don't have to make sure the value is the proper type at all times, only when differentiating between Number and Integer. This allows us to drop range checks and allow any Integer and any Number even if they are not representable in Flash Player.

This should improve performance in most cases, where we don't need a range check. This introduces overflow checks in op_add and op_subtract, but they should be faster than range checks which happened after each op anyway.

  • TODO benchmarks

@kjarosh kjarosh added A-avm2 Area: AVM2 (ActionScript 3) T-perf Type: Performance Improvements labels Oct 14, 2025
@kjarosh kjarosh force-pushed the value-any-i32 branch 2 times, most recently from 5838932 to 81fd313 Compare October 15, 2025 08:36
@kjarosh
Copy link
Member Author

kjarosh commented Oct 15, 2025

Using https://github.com/joelgwebber/bench2d/tree/master/as3:

Benchmark Before After
Bench2dNape (ms/frame) 60.61328125 57.19921875
60.828125 57.35546875
62.2890625 57.81640625
62.30078125 57.609375
61.48046875 59.1484375
Bench2dNape (avg) 61.50234375 57.82578125 (-5.9%)
Bench2d (ms/frame) 147.84765625 148.12109375
145.1875 151.08203125
144.90234375 148.09375
146.26171875 147.44921875
145.08984375 147.76953125
Bench2d (avg) 145.8578125 148.503125 (+1.8%)

This is a performance optimization, as it gets rid of range checks
when operating on values. Since we already implement value
normalization, we don't have to make sure the value is the proper type
at all times, only when differentiating between Number and Integer.
This allows us to drop range checks and allow any Integer and any Number
even if they are not representable in Flash Player.

This should improve performance in most cases, where we don't need a
range check. This introduces overflow checks in op_add and op_subtract,
but they should be faster than range checks which happened after each op
anyway.
@kjarosh
Copy link
Member Author

kjarosh commented Nov 6, 2025

Using https://github.com/joelgwebber/bench2d/tree/master/as3 on WASM:

Benchmark Before After
Bench2dNape (ms/frame) 85.578125 86.95703125
86.06640625 84.79296875
84.7421875 84.97265625
87.171875 86.42578125
Bench2dNape (avg) 85.889648438 85.787109375 (-0.1%)
Bench2d (ms/frame) 224.625 214.875
221.57421875 215.4296875
211.98046875 214.28125
215.57421875 211.5625
Bench2d (avg) 218.438476562 214.037109375 (-2%)

@kjarosh
Copy link
Member Author

kjarosh commented Nov 6, 2025

Using crypto bench (avg of 4):

Before (higher = better):

type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
md2 46466.25 92963.75 99420.25 159222.25 173380.5
md5 359625.5 731572.5 1188434.75 1421335.25 1494247.0
sha1 171086.0 354834.5 565744.0 672837.25 715879.5
sha224 104419.0 212440.0 325887.5 388147.75 406045.0
sha256 99340.5 202623.5 325308.5 381445.75 399629.75
hmac-md5 78351.25 258604.25 681834.25 1139918.75 1455181.0
hmac-sha1 42216.5 136883.5 349474.0 570909.0 703458.5
hmac-sha224 23972.25 79557.5 202619.75 325869.25 409730.0
hmac-sha256 24386.25 78557.0 197033.25 325870.75 403273.0
rc4 2024483.0 2091187.5 2132718.0 2143917.5 2145333.25
xtea-cbc 2704.5 9867.75 34819.75 119784.0 271745.25
aes128-cbc 2086.25 8282.75 28785.0 99619.25 294462.25
aes192-cbc 1777.25 7013.0 26127.5 88121.75 242544.5
aes256-cbc 2252.0 6933.5 24194.5 80006.25 215123.5
blowfish-cbc 4494.0 17797.5 67270.75 238435.75 761295.5
des-cbc 3396.25 12244.75 46445.0 156236.5 404510.75
3des-cbc 1985.5 7746.0 26627.5 79554.5 146203.0

After (higher = better):

type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
md2 47015.5 91857.75 99198.0 159000.25 167763.0
md5 346722.0 701480.0 1143612.75 1332275.25 1433039.5
sha1 169158.25 352704.25 569527.25 673622.5 719749.75
sha224 103010.0 209922.5 337917.5 386057.5 414129.25
sha256 104972.0 211922.25 333058.5 389442.25 424527.25
hmac-md5 76891.5 257206.25 668706.5 1149261.5 1445516.75
hmac-sha1 40332.75 133097.5 341291.0 544766.5 688153.0
hmac-sha224 25437.0 80706.75 203899.0 337235.75 412850.0
hmac-sha256 24813.25 81001.0 202538.5 332786.75 405331.25
rc4 1935978.25 1988855.5 2058805.25 2060748.25 2039964.75
xtea-cbc 2584.5 9782.75 35017.25 113141.25 247642.0
aes128-cbc 2018.75 7917.25 27753.5 96402.75 280187.0
aes192-cbc 1705.25 7006.75 25523.0 86459.0 236282.5
aes256-cbc 2174.5 6832.75 23341.0 79409.5 207649.0
blowfish-cbc 4556.0 17233.75 64999.5 225890.0 731461.5
des-cbc 3602.5 13448.25 49997.25 169752.75 455344.5
3des-cbc 2346.25 7808.0 28968.25 89258.0 172716.25

Diff (lower = better):

type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
md2 -1.18% 1.18% 0.22% 0.13% 3.23%
md5 3.58% 4.11% 3.77% 6.26% 4.09%
sha1 1.12% 0.60% -0.66% -0.11% -0.54%
sha224 1.34% 1.18% -3.69% 0.53% -1.99%
sha256 -5.66% -4.58% -2.38% -2.09% -6.23%
hmac-md5 1.86% 0.54% 1.92% -0.81% 0.66%
hmac-sha1 4.46% 2.76% 2.34% 4.57% 2.17%
hmac-sha224 -6.11% -1.44% -0.63% -3.48% -0.76%
hmac-sha256 -1.75% -3.11% -2.79% -2.12% -0.51%
rc4 4.37% 4.89% 3.46% 3.87% 4.91%
xtea-cbc 4.43% 0.86% -0.56% 5.54% 8.86%
aes128-cbc 3.23% 4.41% 3.58% 3.22% 4.84%
aes192-cbc 4.05% 0.08% 2.31% 1.88% 2.58%
aes256-cbc 3.44% 1.45% 3.52% 0.74% 3.47%
blowfish-cbc -1.37% 3.16% 3.37% 5.26% 3.91%
des-cbc -6.07% -9.82% -7.64% -8.65% -12.5%
3des-cbc -18.1% -0.80% -8.79% -12.1% -18.1%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-avm2 Area: AVM2 (ActionScript 3) T-perf Type: Performance Improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants