Skip to content

perf(dart): typed-container write fast path with scan elimination#3609

Merged
chaokunyang merged 2 commits intoapache:mainfrom
yash-agarwa-l:perf2
Apr 23, 2026
Merged

perf(dart): typed-container write fast path with scan elimination#3609
chaokunyang merged 2 commits intoapache:mainfrom
yash-agarwa-l:perf2

Conversation

@yash-agarwa-l
Copy link
Copy Markdown
Contributor

@yash-agarwa-l yash-agarwa-l commented Apr 23, 2026

Why?

Writing List<T> / Set<T> struct fields paid an O(n) scan to detect heterogeneous types and nulls. Codegen already knows the element type is concrete and non-nullable — the scan is pure overhead.

What does this PR do?

  • Adds writeTypedListPayload<T> / writeTypedSetPayload<T> that resolve TypeInfo once and write the header/type-meta without scanning.
  • Adds writeGeneratedDirectListValue<T> / writeGeneratedDirectSetValue<T> generated-code entry points.
  • Adds a codegen predicate (gated on real Dart DartType nullability) that emits the fast path for non-nullable, non-ref, non-dynamic list/set fields; everything else keeps the existing slow path.

Related issues

#3558

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence of the final clean AI review results from both fresh reviewers on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?
    No user-facing or wire-format change. Serialized bytes are byte-identical to main.

Benchmark

Datatype Operation Fory TPS Protobuf TPS Fastest
Struct Serialize 4,696,615 1,998,625 fory (2.35x)
Struct Deserialize 5,815,245 4,173,568 fory (1.39x)
Sample Serialize 1,744,871 481,801 fory (3.62x)
Sample Deserialize 2,007,877 780,317 fory (2.57x)
MediaContent Serialize 944,111 398,324 fory (2.37x)
MediaContent Deserialize 1,457,065 675,724 fory (2.16x)
StructList Serialize 1,981,716 351,853 fory (5.63x)
StructList Deserialize 2,261,436 596,027 fory (3.79x)
SampleList Serialize 426,153 46,590 fory (9.15x)
SampleList Deserialize 479,900 99,694 fory (4.81x)
MediaContentList Serialize 220,342 76,330 fory (2.89x)
MediaContentList Deserialize 341,839 131,730 fory (2.60x)

@yash-agarwa-l yash-agarwa-l changed the title Perf2 perf(dart): typed-container write fast path with scan elimination Apr 23, 2026
@chaokunyang
Copy link
Copy Markdown
Collaborator

@yash-agarwa-l Could you merge main branch, I've refactored fory dart to support dart web

@yash-agarwa-l
Copy link
Copy Markdown
Contributor Author

@yash-agarwa-l Could you merge main branch, I've refactored fory dart to support dart web

I will do

Copy link
Copy Markdown
Collaborator

@chaokunyang chaokunyang left a comment

Choose a reason for hiding this comment

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

LGTM

@chaokunyang chaokunyang merged commit b71db8a into apache:main Apr 23, 2026
63 checks passed
@yash-agarwa-l yash-agarwa-l deleted the perf2 branch April 23, 2026 12:34
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