Speed up `Display for i256` with a constant 10^38 divisor

Aperta
#12,174 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

Is your feature request related to a problem or challenge?

Part of #11421.

Display for i256 splits a value that does not fit in i128 into up to three 38-digit chunks by dividing by 10^38 twice per value with the generic digit-array div_rem. The divisor is a constant, so a reciprocal can be computed at compile time or once.

Describe the solution you'd like

Use the i256 divisor from #12167 (or a u256 form of it) for the two divisions, and skip the second one when the first quotient is below 10^38. The format_decimal benchmark in arrow-cast has Decimal256 cases with 38 and 76 digits. Confirm they reach Display for i256, and add a case with values between 39 and 76 digits if they don't, in a commit before the change. The PR reports the bot's before and after numbers.

The result must stay identical to today's output for every input, including i256::MIN, whose magnitude does not fit in a signed i256.

Describe alternatives you've considered

Values that fit in i128 already take the to_i128 fast path, and #11530 makes i256::div_rem of magnitudes below 2^128 one u128 division. The benchmark should show how much is left for wider values before this is worth doing.

Additional context

None.

Lingua principale
Rust
Stelle
3.7k
Fork
1.5k
Merge medio
2g 16h
PR unite (30g)
183

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/arrow-rs

Tutte le issue di apache/arrow-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.