Skip to content

Cache encoded field name in FieldEncoder#10296

Merged
Jefffrey merged 3 commits into
apache:mainfrom
massive-com:cached-field-struct-array-encoder
Jul 17, 2026
Merged

Cache encoded field name in FieldEncoder#10296
Jefffrey merged 3 commits into
apache:mainfrom
massive-com:cached-field-struct-array-encoder

Conversation

@MassivePizza

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

See issue.

What changes are included in this PR?

See issue.

Are these changes tested?

Should be covered by existing tests.

Are there any user-facing changes?

No.

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Jul 7, 2026
@MassivePizza
MassivePizza marked this pull request as ready for review July 13, 2026 13:22

@Jefffrey Jefffrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this makes sense to me, though i wonder if we have existing benches that can give some numbers to this improvement? i took a glance but i dont think we have a bench for encoding struct arrays yet

@MassivePizza

Copy link
Copy Markdown
Contributor Author

Right, I forgot to add those. My org has an internal bench for just encode_string and an integration bench for a struct with standard-length field names. Will sanitize those and commit here.

@MassivePizza

Copy link
Copy Markdown
Contributor Author

Sidenote: I also looked at using this caching for DictionaryArrays of String, but our product doesn't really generate those.
We'd have to add an optimization pass in Datafusion to actually produce those for e.g. CASE WHEN that evaluate to constant strings.

@Jefffrey

Copy link
Copy Markdown
Contributor

I ran cargo bench -p arrow --bench json_writer --features "test_utils json" locally with the bench changes on main then on this branch:

bench_integer           time:   [2.4510 ms 2.4599 ms 2.4684 ms]
+                       change: [−4.3634% −3.9909% −3.6416%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 17 outliers among 100 measurements (17.00%)
  8 (8.00%) low severe
  8 (8.00%) low mild
  1 (1.00%) high mild

bench_float             time:   [2.9815 ms 2.9848 ms 2.9883 ms]
+                       change: [−6.1623% −5.8905% −5.6521%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  7 (7.00%) high mild

bench_string            time:   [7.4536 ms 7.4639 ms 7.4741 ms]
+                       change: [−2.7981% −2.5786% −2.3719%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) low mild

bench_mixed             time:   [10.658 ms 10.680 ms 10.705 ms]
+                       change: [−7.4853% −7.1895% −6.9014%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

bench_mixed_longname    time:   [5.1188 ms 5.1363 ms 5.1558 ms]
+                       change: [−28.954% −28.551% −28.156%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  6 (6.00%) high mild
  3 (3.00%) high severe

bench_shortmixed_longname
                        time:   [4.2039 ms 4.2093 ms 4.2148 ms]
+                       change: [−29.683% −29.502% −29.324%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

bench_dict_array        time:   [3.6259 ms 3.6349 ms 3.6446 ms]
+                       change: [−1.7944% −1.5260% −1.2328%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe

bench_struct            time:   [17.071 ms 17.102 ms 17.135 ms]
+                       change: [−2.3589% −2.0595% −1.7670%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  1 (1.00%) low mild
  4 (4.00%) high mild
  2 (2.00%) high severe

bench_nullable_struct   time:   [8.9790 ms 9.0044 ms 9.0332 ms]
-                       change: [+10.464% +10.847% +11.310%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 8 outliers among 100 measurements (8.00%)
  2 (2.00%) high mild
  6 (6.00%) high severe

bench_list              time:   [25.390 ms 25.439 ms 25.492 ms]
-                       change: [+7.6416% +8.2171% +8.7591%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe

bench_nullable_list     time:   [5.4186 ms 5.4606 ms 5.5029 ms]
-                       change: [+4.2082% +5.2798% +6.3134%] (p = 0.00 < 0.05)
                        Performance has regressed.

bench_struct_list       time:   [2.5047 ms 2.5144 ms 2.5257 ms]
+                       change: [−4.4805% −3.7484% −3.0407%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  7 (7.00%) high mild
  2 (2.00%) high severe

f64_to_string           time:   [2.1164 ms 2.1199 ms 2.1236 ms]
+                       change: [−3.0236% −2.7448% −2.4816%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  7 (7.00%) high mild

Benchmarking f32_to_string: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.0s, enable flat sampling, or reduce sample count to 60.
f32_to_string           time:   [1.1920 ms 1.1955 ms 1.1995 ms]
                        change: [+0.5809% +0.8944% +1.2082%] (p = 0.00 < 0.05)
                        Change within noise threshold.

Benchmarking i64_to_string: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.9s, enable flat sampling, or reduce sample count to 50.
i64_to_string           time:   [1.5718 ms 1.5768 ms 1.5818 ms]
                        change: [−1.4256% −1.0300% −0.6526%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild

Benchmarking i32_to_string: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.4s, enable flat sampling, or reduce sample count to 50.
i32_to_string           time:   [1.4531 ms 1.4576 ms 1.4621 ms]
+                       change: [−2.2713% −1.8183% −1.3782%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  6 (6.00%) high mild
  1 (1.00%) high severe

mixed_numbers_to_string time:   [7.1889 ms 7.2025 ms 7.2169 ms]
-                       change: [+4.0331% +4.3315% +4.6342%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 5 outliers among 100 measurements (5.00%)
  4 (4.00%) high mild
  1 (1.00%) high severe

Can see clear improvements on the longname ones 🚀

I think the other regressions are just noise 🤔

Curious if you see similar results

@Jefffrey
Jefffrey merged commit f886978 into apache:main Jul 17, 2026
27 checks passed
@Jefffrey

Copy link
Copy Markdown
Contributor

thanks @MassivePizza

@MassivePizza

Copy link
Copy Markdown
Contributor Author

Just tried one and got an improvement, so probably noise.

bench_nullable_struct   time:   [8.0262 ms 8.0643 ms 8.1052 ms]
                        change: [−8.1292% −7.4883% −6.8732%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  5 (5.00%) high mild
  1 (1.00%) high severe

@MassivePizza
MassivePizza deleted the cached-field-struct-array-encoder branch July 17, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[arrow-json] avoid excessive encoding of field names in StructArrayEncoder

2 participants