-
Notifications
You must be signed in to change notification settings - Fork 57
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
Loading default DATABASE
is extremely slow in WASM
#26
Milestone
Comments
yannleretaille
added a commit
to yannleretaille/rust-phonenumber
that referenced
this issue
Oct 15, 2020
…g Metadata from the Database This has two benefits: - it results in a ~97% reduction of initiliaztion time the first time a phone number is validated. This is crucial for client side applications. - it prevents the crate from compiling in the unlikely case that Googles Metadata should ever contain invalid regexps (this was tested) In the future it should be investigated if there is other data that could be pre-validated during the build phase fixes whisperfish#26
Wow, @yannleretaille, you rock! Gotta love compile-time guarantees. :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For some reason, the initial deref of the
lazy_static
takes several seconds, locking up the page while the first phone number is either parsed or formatted. After that, it's really snappy. Using the Chrome Dev Tools profiler, it looks like thebincode
deserializing only takes ~40ms and most of the time is spent inDatabase::from
. The callgraph is dominated by closure calls. I can only guess that the WASM backend can't optimize away all the closures as aggressively as the x86 one can?Initializing the database in a web worker won't work, because it doesn't share memory with the main thread. The database is not
Deserialize + Serialize
, so you can't send it over manually either. I considered raw JS interop with one of thelibphonenumber
-based NPM packages out there, but there would be no way to convert the result to aphonenumber::PhoneNumber
, since the struct is encapsulated such that the only way to make one is by parsing from a string. That leaves the most promising option as an unnecessary client type, something likeand leaving the final say to the backend. This is certainly possible, but negates a lot of the benefit of having a unified client+server in full-stack Rust.
The text was updated successfully, but these errors were encountered: