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

Avoid regex crate for wasm bundle size (to keep cloudflare free plan) #5008

Closed
mizchi opened this issue Sep 28, 2024 · 2 comments · Fixed by #5018
Closed

Avoid regex crate for wasm bundle size (to keep cloudflare free plan) #5008

mizchi opened this issue Sep 28, 2024 · 2 comments · Fixed by #5018
Assignees
Milestone

Comments

@mizchi
Copy link

mizchi commented Sep 28, 2024

This PR significantly increases the prisma-engine wasm build and makes it impossible to build with the free Cloudflare Workers plan!

image

over 1M (cloudflare limit) for pogtgress

#5002 (comment)

Problem

In fact, regex crate is getting into the runtime on this line

https://github.com/prisma/prisma-engines/pull/5002/files#diff-7a3b1196bc58de119ae8a5d92271b4749892576c8a8548394ce5e17ca9019186R1-R37

I have done some preliminary research on this and it is +650k if you bundle rust regex crate with wasm.

(these are my notes in Japanese, sry)
https://zenn.dev/mizchi/scraps/413cd989324fc7

Solution.

For simple regular expressions like this one, you can solve it by switching to borrow the regex engine from the JS host in js_sys::RegExp.

https://rustwasm.github.io/wasm-bindgen/api/js_sys/struct.RegExp.html

Here's a simple snippet that uses it.

use js_sys::RegExp;
#[wasm_bindgen].
pub fn regex_exec(input: &str) -> bool {
  let expr = RegExp::new(r"\w+", "u");
  expr.test(input)
}
@mizchi mizchi changed the title Avoid regex crate due to wasm bundle size Avoid regex crate for wasm bundle size (to keep cloudflare free plan) Sep 28, 2024
@aqrln

This comment was marked as outdated.

@mizchi
Copy link
Author

mizchi commented Oct 25, 2024

thx @jkomyno @aqrln

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

Successfully merging a pull request may close this issue.

3 participants