Skip to content

use Exception.clone instead of copy constructor#6493

Merged
mikea merged 1 commit into
mainfrom
maizatskyi/2026-04-03-exception-clone
Apr 16, 2026
Merged

use Exception.clone instead of copy constructor#6493
mikea merged 1 commit into
mainfrom
maizatskyi/2026-04-03-exception-clone

Conversation

@mikea

@mikea mikea commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Downstream of capnproto/capnproto#2615

@mikea mikea requested review from a team as code owners April 3, 2026 18:33
@ask-bonk

ask-bonk Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

This is correct — emplace() returns a reference to the emplaced value, then .clone() is called on it to make a copy for throwFatalException. The original was kj::cp(permanentException.emplace(...)) which is equivalent.

I've now reviewed the entire diff thoroughly. This is a mechanical change across 42 files:

  1. Replace kj::cp(exception) with exception.clone() (the bulk of the change)
  2. Replace exception.map([](const kj::Exception& e) { return kj::cp(e); }) with exception.map([](const kj::Exception& e) { return e.clone(); })
  3. Fix ErrorWorkerInterface constructor to properly kj::mv() instead of implicitly copying (a pre-existing minor bug that now surfaces because copy ctor is hidden)
  4. Change AbortSignal::abortException parameter from by-value to const& (since it no longer needs to be copied, and reason.clone() is used inside)
  5. Change QueueEvent::setCompletionStatus to use kj::mv() and return const& from getter
  6. Update deps (capnp-cpp and workerd-cxx) hashes
  7. Remove NOLINT comment in test.h macro (no longer using copy constructor)

All transformations are correct and consistent. The dependency bump, the ErrorWorkerInterface fix, and the abortException signature change are the only non-mechanical parts, and they're all correct. There are no backward compatibility concerns, no security issues, and no logic bugs.

LGTM

github run

@jasnell jasnell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh that's going to be some difficult muscle memory to retrain... but makes sense.

@codspeed-hq

codspeed-hq Bot commented Apr 3, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 40.18%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 71 untouched benchmarks
⏩ 129 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
simpleStringBody[Response] 27.2 µs 19.4 µs +40.18%

Comparing maizatskyi/2026-04-03-exception-clone (fe2f924) with main (22c1ca0)2

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (fe2f924) during the generation of this report, so 22c1ca0 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@mikea mikea force-pushed the maizatskyi/2026-04-03-exception-clone branch from e00eedf to 8bd3e28 Compare April 16, 2026 15:59
@mikea mikea requested a review from a team as a code owner April 16, 2026 15:59
@github-actions

github-actions Bot commented Apr 16, 2026

Copy link
Copy Markdown

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@mikea mikea force-pushed the maizatskyi/2026-04-03-exception-clone branch from 8bd3e28 to 6578d64 Compare April 16, 2026 16:09
@mikea mikea force-pushed the maizatskyi/2026-04-03-exception-clone branch from 6578d64 to fe2f924 Compare April 16, 2026 20:59
@mikea mikea enabled auto-merge April 16, 2026 20:59
@mikea mikea merged commit d1e13ad into main Apr 16, 2026
21 of 23 checks passed
@mikea mikea deleted the maizatskyi/2026-04-03-exception-clone branch April 16, 2026 21:12
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