The original scale function takes around 800ns/op with more
than 10 allocations. It significantly slow down scheduler
and other components that heavily relys on resource pkg.
For more information see #18126.
This pull request tries to optimize scale function. It takes
two approach:
1. when the value is small, only use normal math ops.
2. when the value is large, use math.Big with buffer pool.
The final result is:
BenchmarkScaledValueSmall-4 20000000 66.9 ns/op 0 B/op 0 allocs/op
BenchmarkScaledValueLarge-4 2000000 711 ns/op 48 B/op 1 allocs/op
I also run the scheduler benchmark again. It doubles the throughput of
scheduler for 1000 nodes case.