Skip to content

Comments

[Swift] Uses a pointer based stack instead of native array#8891

Merged
mustiikhalil merged 2 commits intogoogle:masterfrom
mustiikhalil:mmk/move-to-use-pointer-stack
Feb 12, 2026
Merged

[Swift] Uses a pointer based stack instead of native array#8891
mustiikhalil merged 2 commits intogoogle:masterfrom
mustiikhalil:mmk/move-to-use-pointer-stack

Conversation

@mustiikhalil
Copy link
Collaborator

Uses a pointer based stack instead of native array, the performance sometimes struggles when using native arrays thus switching to a custom structure gave the flexbuffer implementation a bit of a speed up. As shown below, twitter encoding became a bit faster, but we still struggle with the bigger chunks like Canada data set.

Stack:



│ Benchmarks:canada-encode-manual-FlexbufferSharedKeys (ns) *            │      3121 │      3254 │      3269 │      3285 │      3310 │      3418 │      3850 │       919 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-manual-FlexbufferSharedKeysAndStrings (ns) *  │      3036 │      3201 │      3234 │      3277 │      3293 │      3377 │      3782 │       928 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-manual-FlexbufferSharedKeys (ns) *           │       265 │       296 │       297 │       299 │       302 │       313 │       365 │     10065 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-manual-FlexbufferSharedKeysAndStrings (ns) * │       587 │       650 │       656 │       661 │       668 │       687 │       760 │      4569

Previous implementation:



│ Benchmarks:canada-encode-manual-FlexbufferSharedKeys (ns) *            │      3023 │      3238 │      3275 │      3344 │      3432 │      3518 │      3834 │       908 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-manual-FlexbufferSharedKeysAndStrings (ns) *  │      3230 │      3463 │      3521 │      3547 │      3588 │      3641 │      3759 │       855 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-manual-FlexbufferSharedKeys (ns) *           │       300 │       330 │       336 │       340 │       345 │       353 │       423 │      8912 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-manual-FlexbufferSharedKeysAndStrings (ns) * │       621 │       679 │       685 │       689 │       691 │       707 │       779 │      4388 │
╘════════════════════════════════════════════════════════════════════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╛

@github-actions github-actions bot added the swift label Dec 30, 2025
@mustiikhalil mustiikhalil force-pushed the mmk/move-to-use-pointer-stack branch 7 times, most recently from cfde57e to 3688211 Compare December 30, 2025 10:44
@mustiikhalil mustiikhalil self-assigned this Jan 4, 2026
… array for improved performance

Remove custom flags for native arrays when using flexbuffers on Wasm
@mustiikhalil mustiikhalil force-pushed the mmk/move-to-use-pointer-stack branch from 3688211 to 866521e Compare February 11, 2026 22:49
@aardappel
Copy link
Collaborator

Kinda sad their builtin arrays are implemented so badly that doing it custom is that much faster..

@mustiikhalil
Copy link
Collaborator Author

@aardappel they arent completely bad, but the issue is the hand holding they have in terms of their implementations. Thus they gave developers the option to use the RandomAcessCollection, which just an array but you have a bit of power in terms of how to use them

@mustiikhalil mustiikhalil merged commit d71c0ab into google:master Feb 12, 2026
50 checks passed
@mustiikhalil mustiikhalil deleted the mmk/move-to-use-pointer-stack branch February 12, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants