Skip to content

Performance: Whiskers Regexes Cache+Optimize#16736

Merged
msooseth merged 3 commits into
argotorg:developfrom
DanielVF:regex-speedup
May 20, 2026
Merged

Performance: Whiskers Regexes Cache+Optimize#16736
msooseth merged 3 commits into
argotorg:developfrom
DanielVF:regex-speedup

Conversation

@DanielVF
Copy link
Copy Markdown
Contributor

@DanielVF DanielVF commented May 18, 2026

Description

3% compile time improvement for --via-ir complilation+optimization and large solidity files, over 100 runs for this change and a baseline.

Adding the 'std::regex_constants::optimize' flag increases the compile time for the regex, but reduces the run time each time it is used. Adding const to the regex creation, means that we only pay this penalty once, but benefit from it each run.
(The const change alone makes a small speedup, while optimize without the const makes a slowdown, since the extra computation for optimization isn't worth it unless the regex object is used multiple times.)

Checklist

Al Disclosure

  • No Al tools were used
  • Al tools were used

DanielVF added 2 commits May 18, 2026 15:18
Reuse static optimized regex objects in Whiskers template validation and rendering. On the target via-IR benchmark this regex-only variant measured 1.0335s warm average versus the 1.0640s baseline.
@msooseth
Copy link
Copy Markdown
Contributor

First of all, thanks! Looks very neat, I hope we can merge this within a week or so.

Scheduled the run on our benchmarking setup, https://github.com/argotorg/solc-bench/ I'll post the compare table generated by it, here, soon.

@DanielVF
Copy link
Copy Markdown
Contributor Author

Running my own wider benchmark made the results better. Looking forward to yours.

contract solc-regex-speedup
ENSRegistryWithFallback -6.30% ✅
FiatTokenV2_2 -4.52% ✅
Poap -3.75% ✅
OCRConfigurationStoreEVMSimple -4.33% ✅
EtherfiLiquidityPool -3.96% ✅
UniswapV3Pool -1.54% ✅
EulerSwap -3.84% ✅
Morpho -4.62% ✅
BoredApeYachtClub -4.84% ✅
WETH9 -6.31% ✅
OETH -3.94% ✅
Vault -7.60% ✅
PoolManager 2.73% ✅
TetherToken -5.01% ✅
RocketDepositPool -3.50% ✅
AaveV4HubInstance -2.89% ✅
Total - 3.72% ✅

@msooseth
Copy link
Copy Markdown
Contributor

OOoo that's a nice set! Might steal that :D Do you wanna make a PR to solc-bench adding these? Otherwise, I'll add them :) But you know, while I like stealing, I'd rather you gave them away 😆

@DanielVF
Copy link
Copy Markdown
Contributor Author

It's my list from purplebench, available here: https://github.com/DanielVF/purplebench/tree/master/suite/contracts

If you import them, you could probably rename the actual contract name in the code to be clearer.

I tried to select a set of important contracts with high TLV / transactions across a couple different domains. I then ripped out the pragmas, and upgraded the code to run on the latest compiler versions.

@msooseth
Copy link
Copy Markdown
Contributor

We should review and merge this asap :)

matesoos@bench-01:~/ > solc-bench compare out-84/bench-results.json out-85/bench-results.json
Baseline: 0.8.36-ci.2026.5.20+commit.bbdb1192.Linux.g++
Target:   0.8.36-ci.2026.5.18+commit.14c06b80.Linux.g++
Δ% = (target - baseline) / baseline. Negative = improvement (lower is better), positive = regression.
winner = '~noise' unless the gap passes a Welch t-test and |Δ%| ≥ 0.1%.

Benchmark           Pipeline  Metric         Base                   Target                 Δ%      winner
------------------  --------  -------------  ---------------------  ---------------------  ------  --------
openzeppelin-5.6.1  evmasm    cpu_time       21.2580s ± 0.0469s     20.1791s ± 0.0188s     -5.07%  TARGET
                              creation_size  725,287 ± 0            725,287 ± 0            0.0%    tie
                              cycles         73.9311G ± 183.6215M   70.2021G ± 54.8143M    -5.04%  TARGET
                              instructions   153.3280G ± 133        143.5489G ± 101        -6.38%  TARGET
                              peak_rss       1079 ± 0 MiB           1029 ± 0 MiB           -4.65%  TARGET
                              runtime_size   650,752 ± 0            650,752 ± 0            0.0%    tie
                              wall_time      21.4028s ± 0.0423s     20.3142s ± 0.0192s     -5.09%  TARGET

openzeppelin-5.6.1  ir        cpu_time       58.2292s ± 0.0596s     54.9075s ± 0.0298s     -5.7%   TARGET
                              creation_size  675,405 ± 0            675,405 ± 0            0.0%    tie
                              cycles         206.0595G ± 165.6536M  194.1818G ± 97.5866M   -5.76%  TARGET
                              instructions   345.3348G ± 421        314.0512G ± 550        -9.06%  TARGET
                              peak_rss       1469 ± 0 MiB           1469 ± 0 MiB           -0.01%  ~noise
                              runtime_size   598,355 ± 0            598,355 ± 0            0.0%    tie
                              wall_time      58.5378s ± 0.0592s     55.2003s ± 0.0279s     -5.7%   TARGET

solady-0.1.26       evmasm    cpu_time       30.9631s ± 0.0698s     29.9096s ± 0.0371s     -3.4%   TARGET
                              creation_size  1,514,791 ± 0          1,514,791 ± 0          0.0%    tie
                              cycles         107.3551G ± 241.1873M  103.5929G ± 120.1126M  -3.5%   TARGET
                              instructions   238.1581G ± 48         227.8504G ± 61         -4.33%  TARGET
                              peak_rss       1828 ± 0 MiB           1829 ± 0 MiB           +0.02%  ~noise
                              runtime_size   1,480,154 ± 0          1,480,154 ± 0          0.0%    tie
                              wall_time      31.1885s ± 0.0594s     30.1072s ± 0.0332s     -3.47%  TARGET

solady-0.1.26       ir        cpu_time       153.4674s ± 0.1285s    148.9563s ± 0.0477s    -2.94%  TARGET
                              creation_size  1,681,895 ± 0          1,681,895 ± 0          0.0%    tie
                              cycles         545.3756G ± 470.5243M  529.1946G ± 190.1463M  -2.97%  TARGET
                              instructions   864.1106G ± 257        825.6569G ± 822        -4.45%  TARGET
                              peak_rss       2949 ± 0 MiB           2951 ± 0 MiB           +0.06%  ~noise
                              runtime_size   1,650,497 ± 0          1,650,497 ± 0          0.0%    tie
                              wall_time      154.2492s ± 0.1354s    149.7210s ± 0.0490s    -2.94%  TARGET

prb-math-4.1.1      evmasm    cpu_time       7.4446s ± 0.0040s      7.2230s ± 0.0066s      -2.98%  TARGET
                              creation_size  252,039 ± 0            252,039 ± 0            0.0%    tie
                              cycles         24.1709G ± 12.0640M    23.3967G ± 7.6477M     -3.2%   TARGET
                              instructions   54.2630G ± 179         52.2839G ± 25          -3.65%  TARGET
                              peak_rss       1174 ± 0 MiB           1175 ± 0 MiB           +0.03%  ~noise
                              runtime_size   250,178 ± 0            250,178 ± 0            0.0%    tie
                              wall_time      7.4909s ± 0.0096s      7.2710s ± 0.0053s      -2.94%  TARGET

prb-math-4.1.1      ir        cpu_time       30.0269s ± 0.0446s     28.1801s ± 0.0275s     -6.15%  TARGET
                              creation_size  262,432 ± 0            262,432 ± 0            0.0%    tie
                              cycles         104.6689G ± 149.5207M  98.0815G ± 92.5648M    -6.29%  TARGET
                              instructions   166.2480G ± 141        149.6574G ± 115        -9.98%  TARGET
                              peak_rss       1499 ± 0 MiB           1495 ± 0 MiB           -0.26%  TARGET
                              runtime_size   260,832 ± 0            260,832 ± 0            0.0%    tie
                              wall_time      30.1784s ± 0.0492s     28.3255s ± 0.0316s     -6.14%  TARGET

forge-std-1.16.1    evmasm    cpu_time       9.5044s ± 0.0098s      9.1102s ± 0.0101s      -4.15%  TARGET
                              creation_size  394,603 ± 0            394,603 ± 0            0.0%    tie
                              cycles         32.8771G ± 21.9855M    31.4795G ± 42.4348M    -4.25%  TARGET
                              instructions   69.7060G ± 58          66.0173G ± 52          -5.29%  TARGET
                              peak_rss       532 ± 0 MiB            532 ± 0 MiB            +0.03%  ~noise
                              runtime_size   381,729 ± 0            381,729 ± 0            0.0%    tie
                              wall_time      9.5606s ± 0.0165s      9.1596s ± 0.0105s      -4.19%  TARGET

forge-std-1.16.1    ir        cpu_time       38.2680s ± 0.0157s     36.8527s ± 0.0204s     -3.7%   TARGET
                              creation_size  422,073 ± 0            422,073 ± 0            0.0%    tie
                              cycles         135.6666G ± 59.0151M   130.5982G ± 75.1305M   -3.74%  TARGET
                              instructions   202.9529G ± 111        190.5684G ± 27         -6.1%   TARGET
                              peak_rss       807 ± 0 MiB            806 ± 0 MiB            -0.03%  ~noise
                              runtime_size   406,750 ± 0            406,750 ± 0            0.0%    tie
                              wall_time      38.4725s ± 0.0123s     37.0323s ± 0.0224s     -3.74%  TARGET

v4-core-4.0.0       evmasm    cpu_time       19.6607s ± 0.0154s     18.6356s ± 0.0109s     -5.21%  TARGET
                              creation_size  2,012,188 ± 0          2,012,188 ± 0          0.0%    tie
                              cycles         68.6066G ± 55.6035M    64.9725G ± 48.5798M    -5.3%   TARGET
                              instructions   146.4592G ± 117        136.9399G ± 92         -6.5%   TARGET
                              peak_rss       878 ± 0 MiB            878 ± 0 MiB            -0.06%  ~noise
                              runtime_size   1,983,262 ± 0          1,983,262 ± 0          0.0%    tie
                              wall_time      19.7958s ± 0.0169s     18.7621s ± 0.0170s     -5.22%  TARGET

v4-core-4.0.0       ir        cpu_time       98.9897s ± 0.0480s     95.3754s ± 0.0309s     -3.65%  TARGET
                              creation_size  1,804,635 ± 0          1,804,635 ± 0          0.0%    tie
                              cycles         351.9026G ± 199.9921M  338.9764G ± 120.6458M  -3.67%  TARGET
                              instructions   552.4681G ± 242        521.1783G ± 393        -5.66%  TARGET
                              peak_rss       1730 ± 0 MiB           1737 ± 0 MiB           +0.4%   BASELINE
                              runtime_size   1,777,945 ± 0          1,777,945 ± 0          0.0%    tie
                              wall_time      99.4856s ± 0.0475s     95.8576s ± 0.0336s     -3.65%  TARGET

morpho-blue-1.0.0   evmasm    cpu_time       11.2212s ± 0.0072s     10.7366s ± 0.0056s     -4.32%  TARGET
                              creation_size  802,290 ± 0            802,290 ± 0            0.0%    tie
                              cycles         39.1200G ± 28.6438M    37.3955G ± 18.3074M    -4.41%  TARGET
                              instructions   84.1987G ± 41          79.8038G ± 48          -5.22%  TARGET
                              peak_rss       512 ± 0 MiB            513 ± 0 MiB            +0.08%  ~noise
                              runtime_size   798,085 ± 0            798,085 ± 0            0.0%    tie
                              wall_time      11.2834s ± 0.0018s     10.7951s ± 0.0097s     -4.33%  TARGET

morpho-blue-1.0.0   ir        cpu_time       57.9787s ± 0.0027s     56.4053s ± 0.0222s     -2.71%  TARGET
                              creation_size  753,526 ± 0            753,526 ± 0            0.0%    tie
                              cycles         206.2192G ± 5.5547M    200.5847G ± 88.0881M   -2.73%  TARGET
                              instructions   293.3590G ± 123        280.3763G ± 247        -4.43%  TARGET
                              peak_rss       961 ± 0 MiB            962 ± 0 MiB            +0.06%  ~noise
                              runtime_size   750,240 ± 0            750,240 ± 0            0.0%    tie
                              wall_time      58.2643s ± 0.0021s     56.6845s ± 0.0205s     -2.71%  TARGET

seaport-1.6         evmasm    cpu_time       141.5387s ± 0.0854s    137.0332s ± 0.0436s    -3.18%  TARGET
                              creation_size  13,568,823 ± 0         13,568,823 ± 0         0.0%    tie
                              cycles         494.7027G ± 316.3915M  478.5264G ± 124.6330M  -3.27%  TARGET
                              instructions   1003.0770G ± 700       962.3958G ± 428        -4.06%  TARGET
                              peak_rss       2695 ± 0 MiB           2691 ± 0 MiB           -0.13%  TARGET
                              runtime_size   12,556,893 ± 0         12,556,893 ± 0         0.0%    tie
                              wall_time      142.3613s ± 0.0894s    137.8451s ± 0.0515s    -3.17%  TARGET

solmate-6           evmasm    cpu_time       4.7162s ± 0.0019s      4.4675s ± 0.0020s      -5.27%  TARGET
                              creation_size  279,294 ± 0            279,294 ± 0            0.0%    tie
                              cycles         16.5228G ± 10.1319M    15.6290G ± 8.9752M     -5.41%  TARGET
                              instructions   38.0325G ± 13          35.6660G ± 85          -6.22%  TARGET
                              peak_rss       780 ± 0 MiB            780 ± 0 MiB            -0.04%  ~noise
                              runtime_size   272,389 ± 0            272,389 ± 0            0.0%    tie
                              wall_time      4.7447s ± 0.0100s      4.4957s ± 0.0090s      -5.25%  TARGET

solmate-6           ir        cpu_time       21.0628s ± 0.0274s     20.2663s ± 0.0226s     -3.78%  TARGET
                              creation_size  267,193 ± 0            267,193 ± 0            0.0%    tie
                              cycles         74.8282G ± 96.3023M    71.9785G ± 70.7864M    -3.81%  TARGET
                              instructions   115.2227G ± 75         107.9671G ± 21         -6.3%   TARGET
                              peak_rss       780 ± 0 MiB            780 ± 0 MiB            -0.04%  ~noise
                              runtime_size   259,851 ± 0            259,851 ± 0            0.0%    tie
                              wall_time      21.1662s ± 0.0273s     20.3661s ± 0.0227s     -3.78%  TARGET

@msooseth
Copy link
Copy Markdown
Contributor

It's my list from purplebench, available here: https://github.com/DanielVF/purplebench/tree/master/suite/contracts

OK, stealing it then 😆 😆 😆

Copy link
Copy Markdown
Member

@clonker clonker left a comment

Choose a reason for hiding this comment

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

LGTM!

@msooseth msooseth merged commit 7af01a4 into argotorg:develop May 20, 2026
83 checks passed
@clonker
Copy link
Copy Markdown
Member

clonker commented May 20, 2026

Well, actually - this could've (should've?) gotten a changelog entry as user-visible performance improvement.

@nikola-matic
Copy link
Copy Markdown
Contributor

Well, actually - this could've (should've?) gotten a changelog entry as user-visible performance improvement.

Is there precedent for this? I wouldn't be against it to be honest, could even write a blog post after we merge more in.

@msooseth
Copy link
Copy Markdown
Contributor

BTW, I had a similar, but shittier one at one point in my not very long Solidity life 😆

https://github.com/argotorg/solidity/pull/16549/changes

@clonker
Copy link
Copy Markdown
Member

clonker commented May 20, 2026

Well, actually - this could've (should've?) gotten a changelog entry as user-visible performance improvement.

Is there precedent for this? I wouldn't be against it to be honest, could even write a blog post after we merge more in.

Yep there is! Check the changelog for recent entries. There are a couple in there.

@msooseth
Copy link
Copy Markdown
Contributor

We can add it as a follow-up, perhaps as part of merging #16741 ?

@DanielVF
Copy link
Copy Markdown
Contributor Author

Yes, I'll add to 16741.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants