Skip to content

⚡ [Performance] Optimize O(N) array membership checks to O(1) in bash catalog resolve - #94

Open
Ch3fUlrich wants to merge 2 commits into
mainfrom
perf-catalog-resolve-17493524674060352058
Open

Ch3fUlrich wants to merge 2 commits into
mainfrom
perf-catalog-resolve-17493524674060352058

Conversation

@Ch3fUlrich

Copy link
Copy Markdown
Owner

💡 What: Replaced O(N) string matching array membership checks in catalog_resolve (lib/linux/catalog.sh) with O(1) Bash associative array (hash set) lookups (wanted_set, done_set, visiting_set). Added :- to prevent unbound variable issues when the script runs under set -u.
🎯 Why: To drastically improve the performance of dependency resolution in the bash catalog, avoiding O(N^2) complexity bottlenecks due to repeated string expansions when traversing dependency chains.
📊 Measured Improvement:
Created a 500-node fully-connected dependency mock catalog testing resolution time.

Baseline Performance:

real	0m4.702s
user	0m3.851s
sys	0m0.938s

After O(1) Hash Set Optimization:

real	0m3.171s
user	0m2.067s
sys	0m1.207s

A larger 1000-node mock catalog demonstrated an even bigger speedup (17.2s vs 10.5s), showing that the optimization becomes increasingly valuable as the graph size grows.


PR created automatically by Jules for task 17493524674060352058 started by @Ch3fUlrich

Replaced O(N) string matching membership checks in `catalog_resolve` with O(1) Bash associative array lookups. Also correctly handled `set -u` contexts by using default empty string substitutions for absent keys (`${array[$key]:-}`).
This resolves the performance issue inside the topologically sorted dependency resolution of components, allowing catalog parsing and installation lists to be much faster.

Co-authored-by: Ch3fUlrich <71930650+Ch3fUlrich@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Replaced O(N) string matching membership checks in `catalog_resolve` with O(1) Bash associative array lookups. Also correctly handled `set -u` contexts by using default empty string substitutions for absent keys (`${array[$key]:-}`).
This resolves the performance issue inside the topologically sorted dependency resolution of components, allowing catalog parsing and installation lists to be much faster.

Co-authored-by: Ch3fUlrich <71930650+Ch3fUlrich@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant