mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-07 15:51:08 +00:00
Speed up the Linux incremental rebuild (optimizes packaging step) (#16244)
## Speeds up OrcaSlicer incremental rebuild on Linux
Profiled `build_linux_image.sh`: 96 s, of which 51 s in the dependency
audit.
**`appimage_is_elf_file()`** ran `file` and `grep` per candidate. An
AppDir holds ~9.6k of them, 4.8k being the bundled Python runtime and
none of them ELF: ~19k processes, 14 s. Reads the four-byte magic
instead. Checked against the old result on 4000 files, no disagreement.
**The dependency walk** popped its queue with `"${queue[@]:1}"`, which
rebuilds the whole array each time. At ~4.8k entries that was 22 s of
copying an array around. Uses a read index.
Audit still passes. `shellcheck` v0.11.0, the version CI uses, is clean.
## Notes
The 96 s -> 12.7 s. Measured on a 32-core / 48 GB machine, but the audit
is a serial bash loop, so cores and RAM is not the bottleneck. On slower
hardware the saving should be larger
## Images
<img width="1987" height="782" alt="Screenshot_20261007_092516"
src="https://github.com/user-attachments/assets/96fcb917-38e5-49e7-8cbe-b37be1a2f23a"
/>
<img width="1807" height="742" alt="Screenshot_20261007_092621"
src="https://github.com/user-attachments/assets/4a65ffae-4d59-41f0-a1c7-ee5b49f3c4be"
/>
This commit is contained in:
@@ -23,7 +23,13 @@ appimage_is_host_library() {
|
||||
}
|
||||
|
||||
appimage_is_elf_file() {
|
||||
file -b "$1" 2>/dev/null | grep -q '^ELF '
|
||||
# Read the four-byte ELF magic rather than asking file(1): this runs once per candidate, and an
|
||||
# AppDir holds thousands of them (the bundled Python runtime alone is ~5k files, none of them
|
||||
# ELF). Two processes per call made this ~14 s of a ~95 s image build on its own.
|
||||
local magic
|
||||
[[ -f "$1" && -r "$1" ]] || return 1
|
||||
IFS= read -r -n 4 -d '' magic < "$1" 2>/dev/null
|
||||
[[ $magic == $'\177ELF' ]]
|
||||
}
|
||||
|
||||
appimage_list_direct_dependencies() {
|
||||
|
||||
@@ -118,9 +118,13 @@ bundle_dependency_closure() {
|
||||
# (scripts/check_appimage_libs.sh).
|
||||
local -a search_dirs=("$dst_dir")
|
||||
|
||||
while [ ${#queue[@]} -gt 0 ]; do
|
||||
target="${queue[0]}"
|
||||
queue=("${queue[@]:1}")
|
||||
# Walked with a read index rather than by reslicing the array: "${queue[@]:1}" rebuilds the whole
|
||||
# queue on every pop, so draining it costs O(n^2). At the ~5k entries this bundle reaches that was
|
||||
# ~22 s of the image build spent copying an array around.
|
||||
local head=0
|
||||
while [ "$head" -lt ${#queue[@]} ]; do
|
||||
target="${queue[$head]}"
|
||||
head=$((head + 1))
|
||||
|
||||
if [ ! -e "$target" ] || ! appimage_is_elf_file "$target"; then
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user