Skip to content

Migrate R2Bucket hash properties from jsg::BufferSource#6490

Merged
jasnell merged 1 commit intomainfrom
jasnell/r2-bucket-sha-no-buffersource
Apr 3, 2026
Merged

Migrate R2Bucket hash properties from jsg::BufferSource#6490
jasnell merged 1 commit intomainfrom
jasnell/r2-bucket-sha-no-buffersource

Conversation

@jasnell
Copy link
Copy Markdown
Collaborator

@jasnell jasnell commented Apr 2, 2026

Use the lighterweight/faster jsg::Js* types instead.

Use the lighterweight/faster jsg::Js* types instead.
@jasnell jasnell requested review from guybedford and npaun April 2, 2026 22:29
@jasnell jasnell requested review from a team as code owners April 2, 2026 22:29
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Apr 2, 2026

Good. The analysis is thorough. Let me now review my findings:

Summary of the changes:

  1. Input side (PutOptions struct): Hash fields (md5, sha1, etc.) changed from jsg::BufferSource to jsg::JsRef<jsg::JsBufferSource> in the OneOf. Usage code extracts the handle via getHandle(js) and uses the same .size() and .asArrayPtr() methods.
  2. Output side (Checksums getters): Return type changed from jsg::Optional<jsg::BufferSource> to jsg::Optional<jsg::JsArrayBuffer>. The copyHash helper is simplified to use JsArrayBuffer::create(js, hash) which allocates and copies in one step.

Review findings:

  • Backward compatibility: Safe. The old code was already creating ArrayBuffer (not a view), and the new code returns JsArrayBuffer which is the same JS type. The input type JsBufferSource accepts the same types as BufferSource (ArrayBuffer | ArrayBufferView).
  • Memory safety: The JsBufferSource returned by getHandle() is stack-local and used immediately within the same scope -- safe. The JsArrayBuffer::create copies data -- no dangling reference.
  • GC safety: PutOptions is a transient JSG_STRUCT used as a method parameter; JsRef fields hold strong refs that are consumed immediately. No visitForGc needed, consistent with codebase convention.
  • Performance: This is a net improvement -- JsBufferSource is lighter weight than BufferSource, and JsArrayBuffer::create(js, hash) replaces the more verbose alloc+copy pattern.
  • Code quality: The new copyHash using .map() is cleaner than the old KJ_IF_SOME pattern.

No actionable issues found.

LGTM

github run

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.05882% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.80%. Comparing base (d355743) to head (4ec7143).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/workerd/api/r2-bucket.c++ 47.05% 8 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6490      +/-   ##
==========================================
- Coverage   70.85%   70.80%   -0.05%     
==========================================
  Files         434      434              
  Lines      122159   122269     +110     
  Branches    19153    19184      +31     
==========================================
+ Hits        86551    86577      +26     
- Misses      24287    24347      +60     
- Partials    11321    11345      +24     

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasnell jasnell merged commit f4e5b08 into main Apr 3, 2026
25 checks passed
@jasnell jasnell deleted the jasnell/r2-bucket-sha-no-buffersource branch April 3, 2026 00:26
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.

3 participants