Optimise iteration and lookups - #3
Merged
Merged
Conversation
added 14 commits
April 6, 2024 20:57
Use unsafe methods to skip redundant range checks
Owner
Author
|
Note: Squash commit deleted in favour of branch merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves performance of object iteration and indexing.
For example, calling
indexOfon anArray<uint32_t>object results in repeated calls to thedata()method.Further, the C++ iterator implementation does the same.
A new speed test module has been added to evaulate performance. This uses some moderately large test objects and evaluates how long it takes to iterate through them using three methods:
for(unsigned i=0; i<array.count(); ++i)loopfor(auto: array)indexOfmethodArray has 1000 elements.
Vector has 367 elements, referencing 3208 bytes of string data.
Map<int, String> has 367 elements.
These are the results, in microseconds, on an esp8266:
Optimise iteration and
indexOfoperationThe regular
[]operator andvalueAtmethods include range checks which are costly inside a loop.Adding
unsafemethods skips these checks.Improve Vector search for char argument*
The
indexOfmethod has been specialised forchar*arguments so thatstrlen()only needs to be called once. Previously it was called on every loop iteration.Provide base
==operator which does binary comparisonThis allows easy searching by value (object content).
Rationalise string comparison methods
FlashStrings have three
equalsoverloads forchar*,StringandFlashStringarguments.We also require three
equalsignorecaseequivalents and appropriateoperator==implementations.By adding an
ignoreCaseparameter to all threeequalsmethods we can simplify code.Other improvements
printElement(Print, char)specialization into source filereadmethod out of header