Repository navigation
Conversation
merge_libraries.py: - Run objcopy on each archive's object files in parallel (--jobs, default = number of CPUs). Previously every .obj was processed serially, which left firebase_firestore.lib (Windows Debug) merging on a single core for ~90 min. - Only pass objcopy the symbol renames that actually appear in each input archive (--filter_renames_per_archive, default on). objcopy's cost scales with the size of the redefinition list. - Support llvm-objcopy alongside GNU nm/ar (--binutils_objcopy_is_llvm, autodetected): don't pass GNU BFD target names to llvm-objcopy. package.sh: add -O to use llvm-objcopy (from the tools dir) with GNU nm/ar. cpp-packaging.yml: - Linux and Windows packaging use the runner's llvm-objcopy via -O. GNU objcopy does a linear lookup per symbol in the redefinition list. - Build firebase_cpp_sdk.zip and firebase_cpp_sdk_windows.zip in parallel in the merge job using multithreaded 7-Zip (new zip_package.sh, which verifies file/symlink counts and falls back to Info-ZIP), replacing single-threaded "zip -9" and the separate sequential create-windows-only-package job. - Don't recompress the already-compressed zips when uploading artifacts. build_desktop.py: on Windows, set CL=/MP so that external projects (gRPC, Abseil, Protobuf, Firestore) compile their sources in parallel. Previously grpc.vcxproj and firestore_core.vcxproj compiled on a single core at the end of every Windows build.
Windows Debug packaging still spends 40-50 minutes merging firebase_firestore.lib after all other libraries are done, but the logs don't show where that time goes. Log (at INFO level, enabled by default via --log_timing) how long each phase takes: loading the cache, scanning C and C++ symbols, finding namespaces, computing renames, filtering renames, extracting archives, objcopy, creating the output archive, and saving the cache, along with symbol/demangle cache misses and counts. Also log each input archive that takes longer than --log_timing_archive_threshold seconds (default 10). Every line is tagged with the output library name, since package.sh runs merges in parallel.
Extraction: when an archive contains duplicate object filenames (e.g. grpc.lib), extract_archive() ran "ar xN <count> <archive> <member>" once per object, and each invocation reads through the entire archive. For the Windows x64 Debug grpc.lib (819 objects) this took ~45-50 minutes. Instead, extract in rounds, one "ar xN <n>" invocation per duplicate level with all the applicable member names at once. Output filenames are unchanged. Caching: every product's merge in package.sh scans the same libraries, so the auto-detected namespaces and the C++ symbol renames (938k symbols x 668 namespaces for Windows x64 Debug, 4-6 minutes per merge) are identical each time. Store both in the shared --cache so they're computed once, during the initial "populate cache" run, and reused by the parallel merges. Cache keys include the platform, scanned libraries, namespaces and rename settings.
The previous commit's batched extraction didn't help: the slow part of
"extract archives" for the Windows Debug grpc.lib (~40 minutes) is actually
replace_strings_in_archive(). MSVC archive member names contain directory
separators, so every member name (819 of them for grpc.lib) gets a binary
replacement over the entire archive, and it ran a separate re.sub() pass
over the whole (very large) file for each name.
Do all the replacements in a single pass instead, using one regex built as
a trie of the patterns (so shared prefixes don't make the regex engine try
every alternative at every position), and look up each match's replacement.
The output is byte-for-byte identical to the old implementation.
Also time member renaming separately ("rename members") from extraction.
Switching Windows packaging to llvm-objcopy caused LNK2001 unresolved external symbol errors in Windows Debug integration tests (app_check, database, and firestore) for pre-rename symbols such as p_thread_callback_boringssl, uWS::*, grpc_core::NoDestructSingleton<...>, and grpc_core::arena_detail::ArenaContextTraits<...>. MSVC embeds /INCLUDE: and /EXPORT: directives referencing pre-rename symbol names in the COFF .drectve section. GNU objcopy inadvertently cleared IMAGE_SCN_LNK_INFO on .drectve so MSVC link.exe ignored it, whereas llvm-objcopy preserves IMAGE_SCN_LNK_INFO, causing link.exe to process the stale directives. Strip .drectve alongside .pdata when running objcopy on Windows.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces several optimizations to speed up the build and packaging processes. Key changes include adding support for llvm-objcopy, parallelizing MSBuild compilation on Windows, implementing a faster multithreaded zipping script using 7-Zip, and significantly optimizing merge_libraries.py through parallel object file processing, trie-based regex replacements, caching of namespaces/renames, and per-archive rename filtering. A performance optimization was suggested in scripts/merge_libraries.py to iterate over the smaller archive_symbols set instead of the entire rename_symbols dictionary when filtering renames per archive.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.
Description
This PR optimizes the slowest bottlenecks in
cpp-packaging.yml, reducing end-to-end packaging time from ~4h 01m (241 min) down to ~1h 32m–1h 41m (92–101 min) (~60% faster).42983930100)46997570570)package-windows-x64-Debug-dynamicpackage-windows-x64-Debug-staticpackage-windows-x86-Debug-*package-windows-*-Release-*package-linuxChanges
1. Parallel Windows compilation for external dependencies (
scripts/gha/build_desktop.py)CL=/MPon Windows beforecmake --build. Previously-jonly parallelized across.vcxprojprojects in MSBuild, leaving large external projects (grpc.vcxproj,firestore_core.vcxproj) compiling single-threaded on 1 CPU core at the end of the build.grpc.vcxprojfrom ~25.7m to ~13.7m andfirestore_core.vcxprojfrom ~5.7m to ~2.7m.2. Faster symbol hiding & archive processing (
scripts/merge_libraries.py,build_scripts/desktop/package.sh,.github/workflows/cpp-packaging.yml)replace_strings_in_archive()previously ran a separatere.sub()pass over the entire archive for each member whose name contained path separators (819 full passes over the ~1 GB Windows Debuggrpc.lib, taking ~40–45m). Replaced with a single-pass trie-regex replacement (~26–29s).extract_archive()now extracts archives with duplicate member names in rounds (onear xN <n>call per duplicate level) instead of onearinvocation per object.llvm-objcopy& per-archive rename filtering:objcopycalls across CPUs (--jobs).--redefine-symsper input archive to only symbols present in that archive (--filter_renames_per_archive).package.sh -Oto usellvm-objcopy(hash-table symbol lookup) alongside GNUnm/aron Linux and Windows, instead of GNUbinutils-2.35.1objcopy(linear linked-list lookup)..drectvealongside.pdataon Windows (llvm-objcopypreservesIMAGE_SCN_LNK_INFOon.drectve, unlike GNUobjcopy, which otherwise causes MSVClink.exeto fail withLNK2001on pre-rename/INCLUDE:and/EXPORT:directives).--cacheso the initialfirebase_analyticswarm-up computes them once and the remaining 11 parallel product merges reuse them (cutting Windows x64 Debug Firestorecompute C++ renamesfrom ~4–6m to ~10s).--log_timing(INFO level, enabled by default) to print per-phase timings and slow input archives.3. Parallel multithreaded final SDK zipping (
build_scripts/other/zip_package.sh,.github/workflows/cpp-packaging.yml)zip -9with multithreaded 7-Zip (-mx=6 -mmt=on -snl, verifying file/symlink counts with automatic fallback to Info-ZIP).create-windows-only-packagejob intofinal-merge-packages, staging the Windows-only tree via hard links (cp -al) and zipping both archives in parallel.compression-level: 0onactions/upload-artifactfor the already-compressed.zipoutputs.-9), final zip sizes are ~3–6% larger (~1893 MB vs. ~1837 MB full; ~1008 MB vs. ~953 MB Windows-only).Testing
1060full,183Windows-only).build-desktop-windows-2022-x64-boringsslandtest-desktop-windows-2022-x64-boringssl), along with Android device and iOS simulator tests. (The remaining failures are unrelated FTL emulator / iOS device-target issues.)Type of Change
Place an
xthe applicable box:Notes
Release Notessection ofrelease_build_files/readme.md.