You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR improves performance of `FlashString` library object iteration and indexing.
For example, calling `indexOf` on an `Array<uint32_t>` object results in repeated calls to the `data()` 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:
1. regular `for(unsigned i=0; i<array.count(); ++i)` loop
2. C++ iterator `for(auto: array)`
3. Using the `indexOf` method
Array<int> has 1000 elements.
Vector<String> has 367 elements, referencing 3208 bytes of string data.
Map<int, String> has 367 elements.
These are the results, in microseconds, on an esp8266:
| Operation | Current | With this PR |
-------------------------------------- | ------------ | ------------ |
| Array<int> for-loop | 1603 | 1611 |
| Array<int> iterator | 1326 | 403 |
| Array<int>.indexOf | 1303 | 425 |
| Vector<String> for-loop | 800 | 721 |
| Vector<String> iterator | 774 | 402 |
| Vector<String> indexOf(const char*) | 6634 | 969 |
| Vector<String> indexOf(String) | 849 | 476 |
| Map<int, String> for-loop | 1042 | 1085 |
| Map<int, String> iterator | 891 | 577 |
| Map<int, String> indexOf | 189 | 189 |
| Map<int, String> lookup | 168 | 168 |
**Optimise iteration and `indexOf` operation**
The regular `[]` operator and `valueAt` methods include range checks which are costly inside a loop.
Adding `unsafe` methods skips these checks.
**Improve Vector search for char* argument**
The `indexOf` method has been specialised for `char*` arguments so that `strlen()` only needs to be called once. Previously it was called on every loop iteration.
**Provide base `==` operator which does binary comparison**
This allows easy searching by value (object content).
**Rationalise string comparison methods**
FlashStrings have three `equals` overloads for `char*`, `String` and `FlashString` arguments.
We also require three `equalsignorecase` equivalents and appropriate `operator==` implementations.
By adding an `ignoreCase` parameter to all three `equals` methods we can simplify code.
**Other improvements**
- Use const references instead of copy
- Move copy/invalidate operations to constructors
- Use constexpr where possible for method return values
- Move `printElement(Print, char)` specialization into source file
- Move `read` method out of header
- Add github workflow
- Put strings in flash
0 commit comments