perf: optimize native binary size and startup time#916
Draft
He-Pin wants to merge 1 commit into
Draft
Conversation
e2b5c36 to
20c2b65
Compare
Motivation: The Scala Native binary was 17.7MB and loaded OpenSSL's libcrypto at startup even when hash functions were never called. JVM format-heavy workloads had redundant ASCII range checks for known-safe format strings. Modification: - Add strip post-link step in build.mill to reduce binary size - Lazy-load OpenSSL via dlsym instead of linking at compile time - Cache OpenSSL function pointers and add null checks - Wrap cryptoFuncs dlsym calls in Zone.acquire for C string allocation - Replace generic loadSym with concrete CFuncPtr.fromPtr calls - Revert unnecessary evaluator pattern matching and num visibility changes - Apply scalafmt formatting Result: Reduced native binary size and improved startup time by deferring OpenSSL loading until hash functions are actually used.
20c2b65 to
31be008
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The Scala Native binary was 17.7MB and loaded OpenSSL's libcrypto at startup even when hash functions were never called. JVM format-heavy workloads had redundant ASCII range checks for known-safe format strings.
Modification
build.mill): Addstripstep afternativeLink, saving ~2MB of__LINKEDIT(non-exported symbols)Platform.scala): Removescala-native-cryptodependency; load libcrypto viadlopen/dlsymonly when hash functions (std.md5,std.sha256, etc.) are actually calledInterpreter.scala,Val.scala): DeferStdLibModuleconstruction, static singletons, andInterpreter.stduntil first useStaticOptimizer.scala): DetectAsciiSafeStrLHS in%operator and passsourceAsciiSafe=truetoscanFormat, skipping redundant ASCII range checksResult
__LINKEDITsectionrepeat_formatbenchmarkMost other benchmarks within noise margin (±3%), as lazy stdlib primarily benefits startup time rather than steady-state throughput.
References
nativeLinkdocumentationdlopen/dlsymlazy loading pattern