Skip to content

Conversation

@Vectorized
Copy link
Owner

@Vectorized Vectorized commented Jun 6, 2025

Description

Just leave it in LibBytes since this is quite byte specific, and it's intended for max perf. Wrapping it in LibString will simply add internal function call overhead.

I noticed that my old code in the older indexOf is quite unoptimized and lacks single letter variable names.
It was during a time when I could not fully visualize the stack.
The difference in style will serve as a signal to the reader on how optimized the code is.
Embrace single letter variable names.
Become one with the world stack machine.

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Ran forge fmt?
  • Ran forge test?

Pull requests with an incomplete checklist will be thrown out.

Hyodar and others added 2 commits June 6, 2025 18:01
* Add indexOf for byte needle

* Add new indexOf methods to LibString

* Use fewer operations variant of algorithm

* Add indexOf tests

* Rename methods and get byte as bytes1

* Optimize needle masking

* Add separate tests for indexOfByte

* Ensure result is within bounds
@github-actions
Copy link

github-actions bot commented Jun 6, 2025

Gas Snapshot Comparison Report

Generated at commit : c921c57, Compared to commit : 2650456

Contract Name Test Name Main Gas PR Gas Diff
LibBytesTest testSliceCalldata() 3110 3088 -22
testStaticStructInCalldata() 20805 20870 65
test__codesize() 13230 14432 1202
testIndexOfByte() - 5456 -
LibSortTest testHasDuplicateGas() 297755 - -
testHasDuplicateOriginalGas() 451379 - -
testInsertionSortInts() 80477 80499 22
testInsertionSortPsuedorandom() 63619 63574 -45
testSearchSorted() 118950 118972 22
testSearchSortedAddresses() 251994 251950 -44
testSearchSortedBasicCases() 2222 2244 22
testSearchSortedEdgeCases() 1617 1595 -22
testSearchSortedWithEmptyArray() 687 731 44
testSortAddressesPsuedorandom() 146920 146898 -22
testSortAddressesPsuedorandomBrutalizeUpperBits() 198939 198982 43
testSortAddressesReversed() 45501 45523 22
testSortAddressesSorted() 41137 41114 -23
testSortBasicCase() 1142 1120 -22
testSortInts() 893932 893975 43
testSortMostlySame() 66081 66058 -23
testSortOriginalMostlySame() 208007 208029 22
testSortOriginalPsuedorandom() 283683 283638 -45
testSortOriginalReversed() 156327 156305 -22
testSortPsuedorandom() 140190 140167 -23
testSortSorted() 34545 34523 -22
testSortedDifferenceDifferential() 183079 183034 -45
testSortedUnionDifferential() 216844 216799 -45
testUniquifySorted() 1710 1688 -22
testUniquifySortedWithEmptyArray() 550 528 -22
test__codesize() 25452 23514 -1938

@Vectorized Vectorized merged commit 3f7f8c7 into main Jun 6, 2025
12 of 13 checks passed
@Vectorized Vectorized deleted the index-of-byte branch June 6, 2025 11:04
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.

3 participants