-
Notifications
You must be signed in to change notification settings - Fork 15
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
Variants handling doubles unic-langid binary size #49
Comments
Thank you for the analysis! I'm wondering if there's an equivalent of |
It appeared that the compiler already optimizes Vecs that it can figure out are only going to have 0 or 1 elements, but if it's possible for it to have more than 2 variants, then it has to pull in the extra machinery. I'm not sure how to avoid that. If there's a lighterweight sorting implementation in some crate, that could be an option. But, I wouldn't plan around it; this issue is more for posterity. Maybe a good resolution would be adding a TODO comment suggesting that |
@Manishearth pointed out that |
@sffc - could you test if |
@sffc - I landed the switch to sort_unstable in 0.8. Lmk if that works, and reopen if needed. |
Sorry, finally got around to looking at this again. I have this small Rust function: use wee_alloc::WeeAlloc;
use unic_langid_impl::LanguageIdentifier;
#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn get_langauge(input: &str) {
let loc1 = LanguageIdentifier::from_bytes(input.as_bytes()).unwrap();
let loc2 = LanguageIdentifier::from_bytes("en-US".as_bytes()).unwrap();
alert(&loc1.get_language());
alert(&loc2.get_language());
} I have my toolchain set up here. I use Twiggy to profile the size of the code. With unic-langid-impl-0.7.2 out of the box, I get:
When I comment out the
When I replace
When I use version 0.8.0, I get (after fixing a compile error in my call site):
And finally, if I replace
This is not a very big or comprehensive test, but on the surface it appears as though |
One other observation. It appears that the compiler keeps |
I'm also increasingly thinking that OmnICU would need to be Have you considered making a |
There are some vector libraries that allocate on the stack and don't require std. But we could also use no_std+liballoc instead and this crate should just work, modulo the sort function. We can write our own simpler sort function. |
Thank you @sffc ! I filled spin off. |
I was doing some binary size analysis on unic-langid. Overall it's pretty tight, I think about as tight as possible, except for the
variants.sort();
line, which adds about 40% to the binary weight (from about 3 KB to 5 KB). It also appears that the compiler likes to basically inline the sorting algorithm.The next biggest chunk of binary size comes from the vector operations required when there is more than one variant.
I think in most cases, language tags have 0 or 1 variant.
The text was updated successfully, but these errors were encountered: