core/txpool/blobpool: calculate log1.125 faster (#29300)

This commit is contained in:
Aaron Chen 2024-03-20 21:51:05 +08:00 committed by GitHub
parent 78c102dec5
commit 0444388c74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -23,8 +23,8 @@ import (
"github.com/holiman/uint256" "github.com/holiman/uint256"
) )
// log2_1_125 is used in the eviction priority calculation. // log1_125 is used in the eviction priority calculation.
var log2_1_125 = math.Log2(1.125) var log1_125 = math.Log(1.125)
// evictionPriority calculates the eviction priority based on the algorithm // evictionPriority calculates the eviction priority based on the algorithm
// described in the BlobPool docs for both fee components. // described in the BlobPool docs for both fee components.
@ -57,8 +57,8 @@ func evictionPriority1D(basefeeJumps float64, txfeeJumps float64) int {
// dynamicFeeJumps calculates the log1.125(fee), namely the number of fee jumps // dynamicFeeJumps calculates the log1.125(fee), namely the number of fee jumps
// needed to reach the requested one. We only use it when calculating the jumps // needed to reach the requested one. We only use it when calculating the jumps
// between 2 fees, so it doesn't matter from what exact number with returns. // between 2 fees, so it doesn't matter from what exact number it returns.
// it returns the result from (0, 1, 1.125). // It returns the result from (0, 1, 1.125).
// //
// This method is very expensive, taking about 75ns on a very recent laptop CPU, // This method is very expensive, taking about 75ns on a very recent laptop CPU,
// but the result does not change with the lifetime of a transaction, so it can // but the result does not change with the lifetime of a transaction, so it can
@ -67,7 +67,7 @@ func dynamicFeeJumps(fee *uint256.Int) float64 {
if fee.IsZero() { if fee.IsZero() {
return 0 // can't log2 zero, should never happen outside tests, but don't choke return 0 // can't log2 zero, should never happen outside tests, but don't choke
} }
return math.Log2(fee.Float64()) / log2_1_125 return math.Log(fee.Float64()) / log1_125
} }
// intLog2 is a helper to calculate the integral part of a log2 of an unsigned // intLog2 is a helper to calculate the integral part of a log2 of an unsigned