Skip to content

Increase VpMult batch size#511

Merged
tompng merged 1 commit intoruby:masterfrom
tompng:batch_mult_batchsize
Apr 1, 2026
Merged

Increase VpMult batch size#511
tompng merged 1 commit intoruby:masterfrom
tompng:batch_mult_batchsize

Conversation

@tompng
Copy link
Copy Markdown
Member

@tompng tompng commented Apr 1, 2026

The bottleneck was the number of divmod operation which depends on batch size.
Larger batch size is always better.

batch_size*BASE**2 doesn't need to be less than 2**63-1, it needs to be less than 2**64. We can increase batch size from 8 to 16.

50-350 words multiplication gets about 1.8 times faster

Benchmark

Multiplication time of x*x where x = BigDecimal('999999999'*words). Smaller is better.

words time(v4.1.0) time(master) time(this pull request) memo
1 0.09 ns 0.06 ns 0.06 ns
5 0.18 ns 0.08 ns 0.08 ns
10 0.53 ns 0.17 ns 0.13 ns
50 11.73 ns 2.54 ns 1.50 ns
100 26.99 ns 9.86 ns 5.59 ns v4.1.0 uses NTT mult
200 53.94 ns 37.77 ns 20.96 ns
300 109.03 ns 81.54 ns 46.07 ns
350 110.75 ns 110.43 ns 62.17 ns master uses NTT mult
400 111.62 ns 112.43 ns 80.38 ns
450 113.02 ns 111.27 ns 111.12 ns this pull uses NTT mult

Number of divmod operation which is the bottleneck depends on batch size.
batch_size*BASE**2 doesn't need to be less than 2**63-1, it needs to be less than 2**64. We can increase batch size to 16.
@tompng tompng merged commit f0985b3 into ruby:master Apr 1, 2026
84 checks passed
@tompng tompng deleted the batch_mult_batchsize branch April 1, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant