Repository navigation
Raise mul's OpenSSL routing threshold to match a Control4 controller - #21
Merged
Merged
Conversation
Measured on the dev controller inside a jit="1" driver (every finitelabs driver sets it), mul through lua-openssl only beats pure Lua from about 12 limb products per converted limb, not the 4 that divmod, mod and mod_mul win at. mul now routes at MUL_ROUTE_MIN_RATIO (12); the others keep 4. The same measurement replaces the pure-Lua mod_exp costs recorded in 2026-08: the current code takes 21 ms + 1.34 ms per exponent bit with the JIT and 65 ms + 15.5 ms without, so a Pair-Setup exchange is ~2.5 s or ~28 s in pure Lua, against ~0.04 s through bn.powmod, not minutes.
Contributor
There was a problem hiding this comment.
Approving. Checked at cde0f32:
- Boundary arithmetic. 47x48 is 2256 products for 190 limbs converted, under 12 x 190 = 2280. 48x48 is 2304 for 192, exactly 12. The widened signed-hex operand is 30 limbs against N's 128: 3840 products against 12 x 316 = 3792, so it routes. N times it is 944 hex digits, and 944 mod 6 = 2, so the "-" still shares a chunk.
- Mutations. I tried four. Ratio 11 fails shape 4, and ratio 13 fails shape 5 and the signed-hex test. Pointing
mulback atROUTE_MIN_RATIOfails shape 4. Dropping the^%x+$guard fails only the signed-hex test. The unmutated control passes. - Doc figures. These follow from the fits: 21 + 1.34 x 256 = 0.36 s, x 3072 = 4.1 s. With the JIT off, 4.0 s and 48 s. The exponent bits in Pair-Setup add up to about 1792 (256 + 512 + 1024), which gives 2.46 s with the JIT on, 28.0 s off, and about 0.04 s at 0.02 ms per bit through
bn.powmod(60.97 / 3072). - Tests. bignum and srp pass locally on LuaJIT and Lua 5.5 without the rock. The full CI matrix, including the 0.8.5 job, is green.
Two optional nits, neither blocking:
bignum.is_accelerated's doc cites mod_mul at "3.6 ms in pure Lua against 0.28 ms" per 3072-bit call. That is about 13x, but the new table has no 128,128,128 row, so nothing in the file backs that figure. Adding the row would fix that.srp.lua:403still says "rather than discovering it by hanging". After this PR's wording that reads like the old minutes-long figure. "by stalling" would match.
Contributor
There was a problem hiding this comment.
Re-reviewed at a953786. The new commit only changes comments and markdown, with no code or test changes. The trimmed text still matches the measurements: the JIT-on case is the one that favours pure Lua most, which justifies the ratios without pointing at any consumer. Nothing references the dropped table any more, and the is_accelerated doc no longer quotes the mod_mul figure that had no table row. Full CI matrix is green at this head, including lua-openssl 0.8.5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Measured on the dev controller (2026-10-18: arm64, LuaJIT 2.1.1700206165, lua-openssl 0.8.5) inside a driver with
jit="1"(LuaJIT's JIT on). The figures are pure-Lua time over OpenSSL time, conversions included:With the JIT on,
divmod,modandmod_mulwin at the current threshold of 4 limb products per converted limb, butmulbreaks even near 12. Somulnow routes atMUL_ROUTE_MIN_RATIO(12); the others keepROUTE_MIN_RATIO(4). Without the JIT this gives up at most a few tenths of a millisecond per mid-size multiply.The same session measured pure-Lua
mod_expon the controller:bn.powmod: 5.13 ms (256-bit exponent) and 60.97 ms (full width), matching the old record.The old pure-Lua figure (669 ms per bit, 2026-08-07) doesn't reproduce with the current code in either mode. A Pair-Setup exchange is about 2.5 s in pure Lua with the JIT and about 28 s without, against about 0.04 s through OpenSSL, not minutes. CLAUDE.md,
srp.is_accelerated's doc,bignum.is_accelerated's doc and the README now say so. SRP still needs OpenSSL on Control4: seconds of serialised Lua stall every driver.Tests: the
mulrouting boundary moves to 47x48 (not routed) and 48x48 (exactly 12). The signed-hex test now uses a multiply wide enough to route; removing the hex guard still fails it.make check, plus bignum and srp suites on LuaJIT with and without the 0.8.5 rock, Lua 5.4 with it, and Lua 5.5.Second commit: trims the routing comments to the deciding numbers and drops references to any particular consumer of the library.