mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-10 00:16:59 +00:00
perf: inline unsignedMultiplyHighFallback to eliminate 32K function calls
Trace profiling showed unsignedMultiplyHighFallback at 16.9% of verify
time (32,524 calls × 82ns = 2.674ms). Although called from inside an
inline crossinline lambda, the function itself was a regular dispatch.
Adding @Suppress("NOTHING_TO_INLINE") inline makes the Kotlin compiler
embed the 4-multiply arithmetic directly at each call site, eliminating
all function dispatch overhead.
https://claude.ai/code/session_01EMY5RnXb9rnsyU2KbXrSaY
This commit is contained in:
+7
-1
@@ -52,8 +52,14 @@ internal expect fun unsignedMultiplyHigh(
|
||||
* if b < 0) and the unsigned correction terms (+ (a & (b >> 63)) + (b & (a >> 63))).
|
||||
* Saves ~8 instructions per call on Android < API 31, where this is the hot path
|
||||
* (~30,000 calls per signature verify).
|
||||
*
|
||||
* MUST be inline: this function is called ~32,000 times per verify via the fused
|
||||
* fieldMulReduce crossinline lambda. Without inline, each call is a real function
|
||||
* dispatch (~82ns on ART). With inline, the Kotlin compiler embeds the arithmetic
|
||||
* directly at each call site — zero dispatch overhead.
|
||||
*/
|
||||
internal fun unsignedMultiplyHighFallback(
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
internal inline fun unsignedMultiplyHighFallback(
|
||||
a: Long,
|
||||
b: Long,
|
||||
): Long {
|
||||
|
||||
Reference in New Issue
Block a user