Skip to content

perf: linear-time key lookups in workspace joins#2710

Open
henryiii wants to merge 1 commit into
mainfrom
perf/workspace-join
Open

perf: linear-time key lookups in workspace joins#2710
henryiii wants to merge 1 commit into
mainfrom
perf/workspace-join

Conversation

@henryiii

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Part of the code review in #2706.

Summary

  • Replace keys = [item[key] for item in joined_items] + keys.index(...) with a key_to_index dict built once from the primary items, giving O(1) membership tests and index lookups instead of O(n) per secondary item.
  • The dict is intentionally not updated when secondary items are appended, preserving the existing behaviour that duplicate-keyed secondary items are each appended rather than merged.
  • The full-dict secondary_item not in primary_items comparison in the outer join branch is left as-is (different semantics — full equality check, not keyed).
  • Removes the stale # NB: this will be slow for large numbers of items comment since it no longer applies to the keyed lookups.

Test plan

  • pytest tests/test_workspace.py -q — 253 tests, all passing, no warnings
  • prek -a --quiet — all pre-commit hooks pass with no changes

🤖 Generated with Claude Code

Replace the O(n) list membership and index searches with an O(1) dict
lookup built once from the primary items. The dict is intentionally not
updated when secondary items are appended, preserving the existing
behaviour for duplicate-keyed secondary items. Also removes the stale
"this will be slow" comment.

Assisted-by: ClaudeCode:claude-sonnet-4.6
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@henryiii, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 29 minutes and 58 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 99920a36-c47f-4908-a7e2-ebe97409eb5e

📥 Commits

Reviewing files that changed from the base of the PR and between 0e54a51 and 8c90a28.

📒 Files selected for processing (1)
  • src/pyhf/workspace.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@henryiii henryiii marked this pull request as ready for review June 12, 2026 17:56
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.47%. Comparing base (0e54a51) to head (8c90a28).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2710      +/-   ##
==========================================
- Coverage   98.28%   96.47%   -1.82%     
==========================================
  Files          65       65              
  Lines        4305     4306       +1     
  Branches      465      465              
==========================================
- Hits         4231     4154      -77     
- Misses         46      119      +73     
- Partials       28       33       +5     
Flag Coverage Δ
contrib ?
doctest ?
unittests-3.10 ?
unittests-3.11 96.47% <100.00%> (+<0.01%) ⬆️
unittests-3.12 ?
unittests-3.13 ?
unittests-3.9 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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