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

Polyfills #82

Closed
lionel-rowe opened this issue Aug 23, 2024 · 5 comments
Closed

Polyfills #82

lionel-rowe opened this issue Aug 23, 2024 · 5 comments

Comments

@lionel-rowe
Copy link
Contributor

lionel-rowe commented Aug 23, 2024

Super happy to see this at Stage 3! 🎉

I noticed there's a polyfill under development at es-shims/RegExp.escape and available via NPM, and I've also made my own lightweight one: lionel-rowe/regexp-escape-polyfill. I'll probably add it to JSR and/or NPM at some point, but for now it's just a GitHub repo.

Benchmarks/comparison:

Name Time (avg) Iter/s Bundle size (minified + gzipped) Details
lionel-rowe/regexp-escape-polyfill 1.301 µs 768,315.5 498 B Modern JS/ESM only, with TS support; aims for full compatibility with the spec (verified via test262) but may differ on implementation details.
es-shims/RegExp.escape 11.189 µs 89,373.5 7.1 kB Aims for ES3 compliance; written with CJS modules; more closely follows the implementation details of the algorithm in the spec.
zloirock/core-js 1.567 µs 637,988.6 5.29 kB CoreJS implementation; ES5 (?) support including various other polyfills; written with CJS modules

Anyway, feel free to add this info to the README etc.

@zloirock
Copy link

https://github.com/zloirock/core-js#regexp-escaping

@lionel-rowe
Copy link
Contributor Author

Thanks @zloirock ! Added that to the table

@zloirock
Copy link

zloirock commented Aug 23, 2024

I don't know about perf, but the bundle size for core-js(-pure)/actual/regexp/escape definitely not 88kB -)
https://bundlejs.com/?q=core-js-pure%2Factual%2Fregexp%2Fescape&treeshake=%5B*%5D
https://bundlejs.com/?q=core-js%2Factual%2Fregexp%2Fescape&treeshake=%5B*%5D

@lionel-rowe
Copy link
Contributor Author

lionel-rowe commented Aug 23, 2024

I don't know about perf, but the bundle size for core-js(-pure)/actual/regexp/escape definitely not 88kB -)
https://bundlejs.com/?q=core-js-pure%2Factual%2Fregexp%2Fescape&treeshake=%5B*%5D
https://bundlejs.com/?q=core-js%2Factual%2Fregexp%2Fescape&treeshake=%5B*%5D

Gotta admit I was a little perplexed at how high the numbers looked for es-shims/RegExp.escape and zloirock/core-js. Methodology I'm using is fetching the ESM version via esm.sh then bundling and minifying with esbuild (which in theory should tree shake correctly for ESM bundling). No gzip. Still, 12.8 kB is a long way off of 88 kB, so I guess either esbuild isn't tree shaking properly, esm.sh is adding a massive amount of cruft, or there's a bug in my code. Edit: I've replaced with min+gzipped numbers from bundlejs.com (and bundlephobia in the case of es-shims/RegExp.escape as I can't get it to load properly via any of the CDNs available on bundlejs.com).

@ljharb
Copy link
Member

ljharb commented Aug 23, 2024

(Computing bundle size numbers absent a complete application is always going to be inaccurate due to optimizations and deduplication, and displaying them makes it really easy for people to draw inaccurate conclusions in both directions.)

Thanks! I'll add es-shims and core-js to the readme; when you've published yours to npm, I'd love a PR to add it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants