huff-language / huffmate

A library of modern, hyper-optimized, and extensible Huff contracts with extensive testing and documentation built by Huff maintainers.
https://github.com/pentagonxyz/huffmate
MIT License
437 stars 55 forks source link

Refactor: optimize Hashmap lib with BALLs #139

Open eugenioclrc opened 5 months ago

eugenioclrc commented 5 months ago
Ran 1 test suite in 58.31ms (54.73ms CPU time): 6 tests passed, 0
failed, 0 skipped (6 total tests)
testGetKey(bytes32) (gas: 0 (0.000%)) 
testGetKeys(bytes32,bytes32) (gas: 0 (0.000%)) 
testSetKey(bytes32,bytes32) (gas: 0 (0.000%)) 
testSetKeys(bytes32,bytes32,bytes32) (gas: 0 (0.000%)) 
testSetKeys2D(bytes32,bytes32,bytes32,bytes32) (gas: 0 (0.000%)) 
testSetKeys3D(bytes32,bytes32,bytes32,bytes32,bytes32) (gas: -9 (-0.026%)) 
Overall gas change: -9 (-0.006%)
Maddiaa0 commented 5 months ago

hahahha incredible, ill take a closer look at this tomorrow, tagging @Philogy for the vibes

Philogy commented 5 months ago

Hey, thanks for tagging @Maddiaa0. Exciting to see my BALLS in use. 😁

eugenioclrc commented 5 months ago

I have fix the hash operations, add some extra tests, and add @Philogy recommendations. I think its ready for a second look.

Spoiler alert, not a huge gain, but balls code seems cleaner and easier to read than the raw Huff.

testGetKey(bytes32) (gas: 0 (0.000%)) 
testGetKeys(bytes32,bytes32) (gas: 0 (0.000%)) 
testSetKey(bytes32,bytes32) (gas: 0 (0.000%)) 
testSetKeys(bytes32,bytes32,bytes32) (gas: 0 (0.000%)) 
testSetKeys2D(bytes32,bytes32,bytes32,bytes32) (gas: 0 (0.000%)) 
testSetKeys3D(bytes32,bytes32,bytes32,bytes32,bytes32) (gas: -9 (-0.026%)) 
Overall gas change: -9 (-0.006%)