Skip to content

perf(objects): filter objects by type from their header in Repository.list - #10730

Merged
davidfirst merged 1 commit into
masterfrom
perf/header-only-type-filter
Sep 24, 2026
Merged

davidfirst merged 1 commit into
masterfrom
perf/header-only-type-filter

Conversation

@davidfirst

Copy link
Copy Markdown
Member

Repository.list(types) read and inflated every object file in the scope just to check its type, then discarded almost all of them — most of a scope is file contents, which no caller of list() asks for. It now reads the type from the header in the first 512 bytes (the mechanism bit gc added in #10714) and only reads the full file when the type matches.

This speeds up every list() caller: rebuilding a missing index.json (on scope load, and after every bit clear-cache), bit cat-scope, the bare-scope garbage collector, toObjectList and the doctor's orphan-symlink check. On a 254 MB scope (27k objects) the index rebuild went from ~3.1s to ~1.4s; the full read scales with the scope's bytes and the header read with its object count, so the gap grows on larger scopes.

When a content transformer is registered the header can't be read on its own, so that case keeps the single full read. An object of an unregistered type is still skipped rather than thrown on, as before.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Filter repository objects by type using header-only reads

✨ Enhancement 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Read object types from 512-byte headers before loading matching repository objects.
• Preserve full-file reads when content transformers prevent independent header parsing.
• Cover index rebuilding, transformed content, and unknown object types with repository tests.
Diagram

graph TD
  A["Repository list"] --> B["Object refs"] --> C{"Transformer active?"}
  C -->|Yes| F["Full object read"] --> G["Matching objects"]
  C -->|No| D["Header read"] --> E{"Requested type?"}
  E -->|Yes or incomplete| F
  E -->|No or unknown| H["Skip object"]
Loading
High-Level Assessment

The header-first fast path is the best fit because it reuses the existing object-header parser, avoids inflating dominant Source payloads, and retains a safe full-read fallback for transformers and incomplete headers. Relying on index metadata would not support rebuilding a missing index, while unconditional full reads retain the original performance bottleneck.

Files changed (2) +139 / -15

Enhancement (1) +47 / -15
repository.tsFilter repository listings from compressed object headers +47/-15

Filter repository listings from compressed object headers

• Extracts transformer detection and fixed-size header reading into reusable helpers. Repository listings now reject unrequested types before reading complete files, while transformed content and incomplete headers fall back to full reads and unknown types preserve prior skip behavior.

scopes/scope/objects/objects/repository.ts

Tests (1) +92 / -0
repository.spec.tsTest header-only filtering and full-read fallbacks +92/-0

Test header-only filtering and full-read fallbacks

• Adds repository integration tests proving index reconstruction fully reads only requested object types. It also verifies transformer-enabled repositories retain one full read per object and unregistered header types remain safely skipped.

scopes/scope/objects/objects/repository.spec.ts

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can choose which labels appear on a finding, and whether they show icons or text

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@davidfirst
davidfirst enabled auto-merge (squash) September 24, 2026 14:19
@davidfirst
davidfirst merged commit 1fdeea0 into master Sep 24, 2026
20 checks passed
@davidfirst
davidfirst deleted the perf/header-only-type-filter branch September 24, 2026 14:37
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.

2 participants