ada-url / ada

WHATWG-compliant and fast URL parser written in modern C++, part of Node.js, Redpanda, Kong, Telegram and Cloudflare Workers.
https://ada-url.com
Apache License 2.0
1.34k stars 84 forks source link

perf: optimize `ada::can_parse` more #690

Closed anonrig closed 2 months ago

anonrig commented 3 months ago

This PR continues @CarlosEduR's work, and improves ada::can_parse by 20%

Before

BasicBench_AdaURL_href                  2730 ns         2719 ns       256522 GHz=4.50694 cycle/byte=14.8762 cycles/url=1092.73 instructions/byte=70.5186 instructions/cycle=4.74035 instructions/ns=21.3645 instructions/url=5.17991k ns/url=242.455 speed=297.156M/s time/byte=3.36524ns time/url=247.192ns url/s=4.04544M/s
BasicBench_AdaURL_aggregator_href       1883 ns         1875 ns       373401 GHz=5.03164 cycle/byte=11.4146 cycles/url=838.455 instructions/byte=53.4653 instructions/cycle=4.68394 instructions/ns=23.5679 instructions/url=3.92727k ns/url=166.636 speed=430.991M/s time/byte=2.32023ns time/url=170.432ns url/s=5.86745M/s
BasicBench_AdaURL_CanParse              1476 ns         1470 ns       476278 GHz=5.36533 cycle/byte=9.9604 cycles/url=731.636 instructions/byte=44.8911 instructions/cycle=4.50696 instructions/ns=24.1813 instructions/url=3.29745k ns/url=136.364 speed=549.726M/s time/byte=1.81909ns time/url=133.62ns url/s=7.4839M/s

After

BasicBench_AdaURL_href                  2775 ns         2769 ns       253059 GHz=4.416 cycle/byte=15.0297 cycles/url=1.104k instructions/byte=70.5371 instructions/cycle=4.69318 instructions/ns=20.7251 instructions/url=5.18127k ns/url=250 speed=291.8M/s time/byte=3.42701ns time/url=251.729ns url/s=3.97252M/s
BasicBench_AdaURL_aggregator_href       1893 ns         1888 ns       370239 GHz=5.10638 cycle/byte=11.5842 cycles/url=850.909 instructions/byte=53.302 instructions/cycle=4.60128 instructions/ns=23.4959 instructions/url=3.91527k ns/url=166.636 speed=427.894M/s time/byte=2.33703ns time/url=171.665ns url/s=5.82529M/s
BasicBench_AdaURL_CanParse              1233 ns         1229 ns       568366 GHz=6.05464 cycle/byte=9.05198 cycles/url=664.909 instructions/byte=39.5347 instructions/cycle=4.36751 instructions/ns=26.4437 instructions/url=2.904k ns/url=109.818 speed=657.476M/s time/byte=1.52097ns time/url=111.722ns url/s=8.95079M/s
CarlosEduR commented 3 months ago

Nice work, getting almost to 100% faster now!

CarlosEduR commented 2 months ago

@anonrig good to go