Closed loloicci closed 2 months ago
@loloicci Thank you, but could you explain more about
But, If we adopt it, we need to improve how to calculate the gas cost of the API. Because this benchmark tells us this makes the gas cost cheaper than the proper cost.
It seems uuid/uuid_api_concat is the fastest method, and the gas fee is the lowest.
If the time it takes to generate is not much different, then I think it's fine to consider removing it.
Thank you.
It seems uuid/uuid_api_concat is the fastest method, and the gas fee is the lowest.
The gas cost for calling API is defined by us. It should be in direct proportion to the taken time. Gas cost for uuid/uuid_api_concat is cheaper than proper in comparison to others. (and uuid/uuid_api_separate takes much expensive gas)
Report: Benchmark of UUID Feature
github workflow: https://github.com/loloicci/line-cosmwasm/actions/runs/8520947517/job/23438536428#step:6:276
Result
Description of the benchmark
Benchmarking uuid/without_uuid
This does other than generating a UUID. This is for comparison only making UUID part in later benchmarking.
Contract
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/contracts/bench-uuid/src/contract.rs#L49-L54
Result
Benchmarking uuid/uuid_original
Api/sha1_calculate
.[ADDRESS] [HEIGHT_IN_DECIMAL] [SEQ_IN_DECIMAL]
as the message.Contract
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/contracts/bench-uuid/src/contract.rs#L56-L61
UUID Generation
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/packages/std/src/uuid.rs#L79
Result
Benchmarking uuid/uuid_api
Api/sha1_calculate
.[ADDRESS] [HEIGHT_IN_DECIMAL] [SEQ_IN_DECIMAL]
as the message.Contract
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/contracts/bench-uuid/src/contract.rs#L63-L68
UUID Generation
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/packages/std/src/uuid.rs#L98
Result
Benchmarking uuid/uuid_api_separate
Api/sha1_calculate
.[ADDRESS][HEIGHT_AS_U8x8][SEQ_AS_U8x8]
.[ADDRESS]
,[HEIGHT_AS_U8x8]
, and[SEQ_AS_U8x8]
.Contract
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/contracts/bench-uuid/src/contract.rs#L70-L75
UUID Generation
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/packages/std/src/uuid.rs#L117
Result
Benchmarking uuid/uuid_api_concat
Api/sha1_calculate
.[ADDRESS][HEIGHT_AS_U8x8][SEQ_AS_U8x8]
.Contract
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/contracts/bench-uuid/src/contract.rs#L77-L82
UUID Generation
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/packages/std/src/uuid.rs#L135
Result
Benchmarking uuid/uuid_wasm
Api
but uses only WASM native calculation.[ADDRESS][HEIGHT_AS_U8x8][SEQ_AS_U8x8]
.[ADDRESS]
,[HEIGHT_AS_U8x8]
, and[SEQ_AS_U8x8]
.Contract
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/contracts/bench-uuid/src/contract.rs#L84-L89
UUID Generation
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/packages/std/src/uuid.rs#L152
Result
Benchmarking uuid/uuid_wasm_concat
Api
but uses only WASM native calculation.Api/sha1_calculate
.[ADDRESS][HEIGHT_AS_U8x8][SEQ_AS_U8x8]
.Contract
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/contracts/bench-uuid/src/contract.rs#L91-L96
UUID Generation
https://github.com/loloicci/line-cosmwasm/blob/d3d71312397ec19927e633902db89ece592ef310/packages/std/src/uuid.rs#L168
Result
Suggestion
There are two different suggestions. We need to discuss which is better.
Remove Sha1 API
Removing Sha1 API from our cosmwasm and using the new style messages for generating UUIDs.
Using new style messages, it takes almost the same time to generate a UUID as before even if we do not use API.
Improve the Message And Modify the Gas Cost
Improving the message style and where the messages are concatenated.
These make generating UUIDs faster. But, If we adopt it, we need to improve how to calculate the gas cost of the API. Because this benchmark tells us this makes the gas cost cheaper than the proper cost.