Skip to content

Avoid duplicate hash computation during object creation#2549

Merged
Sebastian Thiel (Byron) merged 4 commits into
mainfrom
no-dupl-compute
May 27, 2026
Merged

Avoid duplicate hash computation during object creation#2549
Sebastian Thiel (Byron) merged 4 commits into
mainfrom
no-dupl-compute

Conversation

@Byron
Copy link
Copy Markdown
Member

@Byron Sebastian Thiel (Byron) commented Apr 28, 2026

Fixes #2516

Tasks

  • refackiew
  • commits with decent changelog entries

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks good to me, just a couple questions about the Write trait changes (TBH I'm really just comparing with the non-known_id variants)

Comment thread gix-object/src/traits/mod.rs Outdated
Comment thread gix-object/src/traits/mod.rs Outdated
@Byron
Copy link
Copy Markdown
Member Author

Jon Ross-Perkins (@jonmeow) Thanks so much for taking a look!

I haven't looked at the code at all yet, but when I do I will particularly look at the places you are highlighting.

Codex (codex) and others added 3 commits May 27, 2026 06:47
Add `write_buf_with_known_id()` and `write_stream_with_known_id()` to the
Write trait without default bodies.
That way it's possible to precompute the hash and avoid recomputing it here.

Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
This means the `Repository::write_object()` won't recalculate the hash.

Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
@Byron Sebastian Thiel (Byron) marked this pull request as ready for review May 26, 2026 23:10
Copilot AI review requested due to automatic review settings May 26, 2026 23:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces write_buf_with_known_id and write_stream_with_known_id on gix_object::Write so callers that already computed an object's hash (e.g. for the existence pre-check in Repository::write_*) can skip the duplicate hash computation performed by the ODB. All ODB layers (sink, loose store, dynamic store, cache, memory proxy) and the &T/Arc/Rc forwarders are updated, and the Repository write paths are switched to the new entry points.

Changes:

  • Adds two new methods to the gix_object::Write trait and forwards them through all wrapper impls.
  • Implements known-ID write paths in sink, loose store (refactored into compressed_tempfile/finalize_object_at), dynamic store, cache, and memory proxy.
  • Rewires Repository::write_object, write_blob, write_blob_stream, and impl Write for Repository to use the known ID, with tests covering loose store and memory proxy.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
gix-object/src/traits/mod.rs Adds the two new (required) trait methods.
gix-object/src/traits/_impls.rs Forwards new methods through &T, Arc<T>, Rc<T>.
gix-odb/src/sink.rs Implements known-ID variants by mirroring the existing compress loop without hashing.
gix-odb/src/store_impls/loose/write.rs Splits hash wrapping/finalization so known-ID writes can bypass hashing.
gix-odb/src/store_impls/dynamic/write.rs Forwards known-ID writes to the first loose DB, initializing if needed.
gix-odb/src/cache.rs Delegates known-ID writes to inner.
gix-odb/src/memory.rs Inserts directly into in-memory map using the given ID, else forwards.
gix/src/repository/object.rs Switches three write sites to write_buf_with_known_id.
gix/src/repository/impls.rs Implements known-ID variants on Repository, including stream-size validation.
gix-odb/tests/odb/store/loose.rs Round-trips known-ID buf/stream writes.
gix-odb/tests/odb/memory.rs Verifies known-ID is trusted (with/without in-memory map).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gix-object/src/traits/mod.rs
@Byron Sebastian Thiel (Byron) merged commit 69caccd into main May 27, 2026
32 checks passed
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.

Add API so that Repository write functions only compute hash once

4 participants