-
Notifications
You must be signed in to change notification settings - Fork 27
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
Encoding::encode_mut
is very code-size heavy
#97
Comments
Thanks for opening an issue! Yes, binary size is a concern for this library, but only with LTO (because it heavily relies on the actual encoding being known at compile time). Are you measuring bloat with full LTO enabled? If yes, could you provide me reproduction steps? There wasn't any heavy benchmarks in that regard and also no CI to check for regressions, so might be a valid issue :-/ |
The reproduction I have is that project, but I don't have enough energy to look into this much further. It uses thin lto, but it's probably a bad idea to rely on LTO in the first place. My suggestion would be to feature-lock each encoding to allow dependents to only enable what they need, avoiding the need to rely on LTO. |
I'm back from vacation and could take a look. However I'm not able to reproduce. I tried
Could you provide me with exact instructions to reproduce (including commit hash). I have an idea that could easily fix the issue but I want to confirm it actually fixes your problem first. Thanks! |
Thanks! I was able to reproduce on your project with |
Sorry for the long delay. I tried to [dependencies]
data-encoding = "2.5" to: [dependencies.data-encoding]
version = "2.6" # not released yet
default-features = false
features = ["std", "base16"] The code size measured with the text column of It is probably possible to do better but it would require quite some refactoring. Would this change be enough for you? The change is in #101 and I'll keep it open until I decide whether it should be a breaking change or not. It is technically one for those who disable default features. |
Actually, I'll probably postpone submitting that PR until I experiment with another idea that would bring much more benefit. I'm just afraid that it might make the API a bit less usable by having many type parameters (a little bit like RustCrypto does). Because if I'll have to make a major version bump, then let's try to make the most out of it. |
Ok, my experiment using |
I don't think so. The current design assumes inlining and dead-code elimination to work cross-crate. This seems to work rather well with LTO but not otherwise. The new design I have in mind (I didn't fully test it though) doesn't rely on inlining by adding one layer of indirection (which can be optimized by inlining) and simplifies dead-code elimination by introducing a symbol for each combination, so the linker can always do it regardless of LTO. |
This new module addresses the following breaking changes of #72: - `static` instead of `const` for pre-defined encodings - Private `Encoding` implementation with `unsafe` constructor - Use `MaybeUninit` internally and expose `_uninit` functions - Use static dispatch instead of dynamic dispatch (fixing #97)
Ok, I got some time to look into this again. I've created the I did the following change: diff --git a/common/Cargo.toml b/common/Cargo.toml
-data-encoding = "2.5"
+data-encoding = { git = "https://github.com/ia0/data-encoding.git", branch = "v3-preview", features = ["v3-preview"] }
diff --git a/common/src/noise.rs b/common/src/noise.rs
-use data_encoding::HEXLOWER_PERMISSIVE;
+use data_encoding::v3_preview::HEXLOWER_PERMISSIVE; For the following measurements:
Where "cargo size" is So this looks pretty good so far. I'll have to finish adding all features to the |
This new module addresses the following breaking changes of #72: - `static` instead of `const` for pre-defined encodings - Private `Encoding` implementation with `unsafe` constructor - Use `MaybeUninit` internally and expose `_uninit` functions - Use static dispatch instead of dynamic dispatch (fixing #97)
This new module addresses the following breaking changes of #72: - `static` instead of `const` for pre-defined encodings - Private `Encoding` implementation with `unsafe` constructor - Use `MaybeUninit` internally and expose `_uninit` functions - Use static dispatch instead of dynamic dispatch (fixing #97)
This new module addresses the following breaking changes of #72: - `static` instead of `const` for pre-defined encodings - Private `Encoding` implementation with `unsafe` constructor - Use `MaybeUninit` internally and expose `_uninit` functions - Use static dispatch instead of dynamic dispatch (fixing #97)
This new module addresses the following breaking changes of #72: - `static` instead of `const` for pre-defined encodings - Private `Encoding` implementation with `unsafe` constructor - Use `MaybeUninit` internally and expose `_uninit` functions - Use static dispatch instead of dynamic dispatch (fixing #97)
This new module addresses the following breaking changes of #72: - `static` instead of `const` for pre-defined encodings - Private `Encoding` implementation with `unsafe` constructor - Use `MaybeUninit` internally and expose `_uninit` functions - Use static dispatch instead of dynamic dispatch (fixing #97)
This is now merged in |
Hello, I've just ran cargo-bloat on my project as I'm working on reducing compile times and binary sizes can be a proxy for compile times, and found that
data_encoding::Encoding::encode_mut
is taking up76.9kb
, the third largest function in my entire project (that pulls reqwest, tungstenite, etc).If code size isn't a concern for this project, I'm entirely fine with this being closed, but thought that you might want a heads up that this library is somewhat code-size heavy.
The text was updated successfully, but these errors were encountered: