Skip to content

Conversation

@stokito
Copy link
Contributor

@stokito stokito commented Feb 26, 2023

I going to reuse a pricer instances and put them to a sync.Pool
In the same time I receiving the encryptedPrice as []byte so on conversion to string it creates an allocation.
Here I extracted a separate method DecodeRaw() that can work directly with []byte.
But also it can reuse a buffer and count of allocations significantly reduced.
Under a heavy load this is a very good thing

The logging is almost useless for users but a developer can debug in IDE.
The raw keys bytes are not saying anything.
We have errors to return a message to a caller.
In the same time the code needs to be compiled and it makes the program slower because it resides in CPU cache.
Remove deprecated isDebugMode
These fields are never read but consumes memory.
If we are going to create many instances of the Pricer then it will consume a lot of memory and make program slower
The function will decode the string key
You can decode the keys one and then create multiple pricers with them.
It will never occur. Even seed is just an empty string the md5 hash will be not empty
The method accepts a price in raw bytes.
It also receives a buffer for decoding which can be reused later
It can be pre-allocated.
This saved one allocation and improved speed
The generated assembly has a cycle to make xor with two arrays p and pad.
Given that the two arrays have only 8 bytes we can convert them to uint64 and perform a usual xor.

The optimization makes code harder to read and saves only about 4ns.
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