-
Notifications
You must be signed in to change notification settings - Fork 17
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
Reduce bundle size of ens_normalize
function
#28
Comments
There are some thoughts here: #21 (comment) With browser detection, it would be possible to use features (like Unicode regex patterns.) I'll update this when I get some time. |
Possible ideas:
I'd estimate (4) is the easiest and could trim the entire NF payload + the bulk of the character data. Also, there might be something I missed in (1) w/r/t compression, as I wrote the compressor in beginning of this project as I had to confirm that it was feasible to jam the entire Unicode character data into the library. Whereas now, the structure of |
Incredible; I appreciate the breakdown, @adraffy! I'm going to be bold here and claim that I likely cannot make the in-the-weeds fixed you've recommended as quality as you could, but I'm happy to take a stab at (4) if it seems this is high-value and you don't have time. Again, my attempt likely won't come close to yours, seeing as I don't have this type of character encoding experience, but I'm happy to learn! |
@dawsbot Worth noting that Viem inverts control so you can use another normalize function (or skip normalization if you know what you are doing). This also means that if you aren't using ENS with Viem, import { normalize } from 'viem/ens' // proxies `ens_normalize` export
const ensAddress = await client.getEnsAddress({
name: normalize('wevm.eth'),
}) import { custom_normalize } from 'custom-normalize' // use whatever normalize you like!
const ensAddress = await client.getEnsAddress({
name: custom_normalize('wevm.eth'),
}) |
I would be very careful with using non-standard normalization. While the bulk of ENS names currently ASCII, I would expect that trend to change in the future. Spoofing names is a serious attack vector—look how many people get scammed by address poisoning. Is the current library size an actual problem? Relative to nearly every site I see, asset and code bloat dwarfs actual library code by a huge margin. The goal of this library is to produce the correct result for ALL inputs across any engine that can run the library. It accomplishes that by internalizing everything (which includes the full Unicode spec). FYI: The major browser vendors can't even agree on URL parsing. When I update the library to Unicode 16 for the September release, I'll revisit the compression logic. |
I can supply a stub function if you want |
Hey @adraffy, I'm not sure if there are any easy wins on the bundle size, but I'm happy to help if so! Do you have any suggested areas to work on?
Seeing as both
ethers
andviem
rely on this library and theens_normalize
function carries somewhere around 25kb into these packages, it might be possible to reduce that? You're the expert, let me know if or how I can help!The text was updated successfully, but these errors were encountered: