Skip to content

perf(compile): use toArrayOf instead of toArray.map(_.asInstanceOf) - #76

Merged
halotukozak merged 1 commit into
mainfrom
perf/compile-toarrayof
Sep 4, 2026
Merged

halotukozak merged 1 commit into
mainfrom
perf/compile-toarrayof

Conversation

@halotukozak

Copy link
Copy Markdown
Collaborator

Summary

deriveProduct already builds most of its arrays with commons' toArrayOf[T] (single-pass, no intermediate Array[Any]) — the three annotation-flag arrays (optionalFlags, transientDefaultFlags, outOfOrderFlags) were the exception, still going through .toArray.map(_.asInstanceOf[Boolean]). Switched them to the same toArrayOf[Boolean] pattern, with an explicit (using containsOnly.refl) — same as the two summonAll[...].toArrayOf[MCodec[Any]] calls just above already do, since the tuple's type after destructuring a 3-way hasAnnotationsByType result doesn't syntactically match the automatic containsOnly given.

Measured (same-session, N=50 generated project, -Yprofile-trace, 3-run mean)

typer inlining total
before 1.58 s 3.29 s 7.49 s
after 1.51 s 3.22 s 7.38 s (−1.5%)

Small, since this only touches codec construction (one array alloc removed per flag column, once per derived type) rather than the read/write hot path — no JMH rerun needed.

Test plan

  • ./mill jvm.test — 186/186 green
  • ./mill js.compile native.compile — clean
  • CI

🤖 Generated with Claude Code

optionalFlags / transientDefaultFlags / outOfOrderFlags already had
containsOnly evidence available (like the two summonAll calls just
above them) — building each flag Array[Boolean] via toArray.map(cast)
allocates an intermediate Array[Any] and boxes/unboxes through it.
toArrayOf[Boolean] builds the Array[Boolean] directly in one pass, same
as the rest of deriveProduct's array construction already does.

Same-session N=50 compile: 7.49s -> ~7.38s (-1.5%); one-time codec
construction cost, not the read/write hot path, so no runtime bench
needed. All 186 tests green (JVM + JS + Native compile clean).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 4, 2026 07:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@halotukozak
halotukozak merged commit 3dcbcf6 into main Sep 4, 2026
7 checks passed
@halotukozak
halotukozak deleted the perf/compile-toarrayof branch September 4, 2026 07:14
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