shanielh opened a new pull request, #12532:
URL: https://github.com/apache/arrow-rs/pull/12532

   # Which issue does this PR close?
   
   - Follow-up to #11982 and #12122 (no issue filed).
   
   # Rationale for this change
   
   The byte array dictionary encoder caches each arrow dictionary value's 
interned index, so a value is hashed once rather than once per row (#11982). It 
starts that cache only when one write references at least as many rows as the 
dictionary has values (#12122).
   
   A dictionary with more values than any one write has rows, shared by the 
writes that follow, never gets a cache: every row is hashed into the interner. 
That is the shape a reader produces when it keeps one dictionary across 
batches, for example slices of one dictionary column, or the batches of an 
external sort whose runs share a dictionary.
   
   # What changes are included in this PR?
   
   - Rows encoded without the cache now count toward the same threshold, for as 
long as consecutive writes carry the same dictionary allocation. Rows are 
counted per call, so a write split into several calls by `write_batch_size` or 
the page limit counts its rows once. A different dictionary in between starts 
the count again. A single write decides exactly as before.
   - The cache keeps its existing cost, one `u64` per dictionary value per 
column chunk, and still starts only once at least that many rows have 
referenced the dictionary.
   - A benchmark, `string_dictionary_shared_by_batches`, as the first commit: 
256 batches of 4,096 rows, slices of one `Dictionary<Int32, Utf8>` column whose 
dictionary has 32,768 values.
   
   # Are these changes tested?
   
   Yes. `use_dictionary_cache_dictionary_shared_by_writes` covers a dictionary 
shared by consecutive writes, a write split into several calls, and another 
dictionary in between. The two existing cache tests are updated for the new 
signature and keep their cases.
   
   Benchmark, Apple M-series laptop, 
`string_dictionary_shared_by_batches/default`:
   
   | | time | throughput |
   |---|---|---|
   | main | 18.46 ms | 56.8 Melem/s |
   | this PR | 9.89 ms | 106.1 Melem/s |
   
   −46% time (p < 0.05).
   
   # Are there any significant user-facing changes?
   
   No. The encoded output is unchanged: the cached path interns each value at 
the first row that references it, as the uncached path does.
   
   # AI usage disclosure
   
   Claude (Anthropic) helped find the cause, write the change, its tests and 
the benchmark, and draft this description. I reviewed and ran all of it.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to