Commit 1d2bea8
authored
feat(dart): support dart web platform (#3608)
## Why?
Dart web builds use JavaScript number semantics, so raw Dart `int`
cannot safely represent the full 64-bit value space used by Fory xlang
integer encodings. The Dart runtime needs browser-compatible buffer,
generated serializer, and 64-bit wrapper implementations that preserve
wire compatibility instead of silently corrupting JS-unsafe values.
## What does this PR do?
- Adds Dart web support through conditional native/web implementations
for `Buffer`, generated cursors, and `Int64` / `Uint64` value and list
wrappers.
- Updates code generation and serializers to handle full-range signed
and unsigned 64-bit fields on web, while keeping Dart `int` fast paths
for JS-safe values.
- Adds explicit range checks so web builds reject JS-unsafe Dart `int`
conversions instead of writing or reading imprecise bytes.
- Extends Dart serializer, buffer, generated-field, numeric-wrapper,
typed-array, and time tests for 64-bit edge cases and browser behavior.
- Adds Chrome test coverage to CI with `dart test -p chrome` for the
Dart package.
- Documents Dart web support, 64-bit integer rules, custom serializer
guidance, and troubleshooting steps.
## Related issues
Closes #3600
## AI Contribution Checklist
- [ ] Substantial AI assistance was used in this PR: `yes` / `no`
- [ ] If `yes`, I included a completed [AI Contribution
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
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?
Yes. Dart users can now use generated serializers and manual serializers
on web/browser targets. Full-range 64-bit values should use `Int64` or
`Uint64`; Dart `int` fields remain limited to JS-safe values on web.
- [x] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<img width="4200" height="900" alt="throughput"
src="https://github.com/user-attachments/assets/ca422bc6-5345-4560-a35a-2678f4c54b9c"
/>
| Datatype | Operation | Fory TPS | Protobuf TPS | Fastest |
| ---------------- | ----------- | --------: | -----------: |
------------ |
| Struct | Serialize | 5,041,693 | 2,073,839 | fory (2.43x) |
| Struct | Deserialize | 6,395,290 | 4,991,881 | fory (1.28x) |
| Sample | Serialize | 1,783,688 | 552,140 | fory (3.23x) |
| Sample | Deserialize | 2,124,197 | 934,794 | fory (2.27x) |
| MediaContent | Serialize | 952,498 | 438,419 | fory (2.17x) |
| MediaContent | Deserialize | 1,649,039 | 737,340 | fory (2.24x) |
| StructList | Serialize | 1,945,119 | 399,007 | fory (4.87x) |
| StructList | Deserialize | 2,119,403 | 764,832 | fory (2.77x) |
| SampleList | Serialize | 475,413 | 52,512 | fory (9.05x) |
| SampleList | Deserialize | 508,939 | 116,236 | fory (4.38x) |
| MediaContentList | Serialize | 224,925 | 84,860 | fory (2.65x) |
| MediaContentList | Deserialize | 387,070 | 154,392 | fory (2.51x) |1 parent ad80be2 commit 1d2bea8
77 files changed
Lines changed: 6216 additions & 1243 deletions
File tree
- .agents/skills/fory-code-review
- .github/workflows
- dart/packages
- fory-test/test/cross_lang_test
- fory
- example
- lib
- src
- codegen
- context
- memory
- meta
- resolver
- serializer
- types
- util
- test
- docs
- benchmarks/dart
- compiler
- guide/dart
- specification
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
24 | 36 | | |
25 | 37 | | |
26 | 38 | | |
27 | 39 | | |
28 | 40 | | |
| 41 | + | |
29 | 42 | | |
30 | 43 | | |
31 | 44 | | |
| |||
63 | 76 | | |
64 | 77 | | |
65 | 78 | | |
| 79 | + | |
66 | 80 | | |
67 | 81 | | |
68 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
999 | 999 | | |
1000 | 1000 | | |
1001 | 1001 | | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
1002 | 1006 | | |
1003 | 1007 | | |
1004 | 1008 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
248 | | - | |
| 247 | + | |
| 248 | + | |
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
17 | | - | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
196 | | - | |
| 197 | + | |
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
202 | | - | |
| 203 | + | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| |||
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
225 | | - | |
226 | | - | |
227 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
228 | 229 | | |
229 | 230 | | |
230 | 231 | | |
| |||
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
236 | | - | |
| 237 | + | |
237 | 238 | | |
238 | 239 | | |
239 | 240 | | |
| |||
257 | 258 | | |
258 | 259 | | |
259 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
260 | 264 | | |
261 | 265 | | |
262 | 266 | | |
| |||
276 | 280 | | |
277 | 281 | | |
278 | 282 | | |
279 | | - | |
280 | | - | |
| 283 | + | |
| 284 | + | |
281 | 285 | | |
282 | 286 | | |
283 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
0 commit comments