fastify / fastify-cors

Fastify CORS
MIT License
414 stars 57 forks source link

refactor(vary): use word character inside regex character class #270

Closed Fdawgs closed 1 year ago

Fdawgs commented 1 year ago

Checklist

Fdawgs commented 1 year ago

Throwing this into a draft for now. @Uzlopak I noticed you've been making regex improvements in Node itself (https://github.com/nodejs/node/pull/49643), do you know if using a \w character over [a-zA-Z0-9_] impacts performance at all?

Uzlopak commented 1 year ago

Tbh i never benched it. And i have no clue if it could have an impact. I mean theoretically \w gets just translated to the specific chars internally. But maybe the regex engine optimizes it somehow.

But on the other hand i never used \w because like 10 years ato I always needed to lookup if i am not mistaking it with \W :))).

Fdawgs commented 1 year ago

Just used the benchmark in benchmark/vary.js

master: image

PR:

image