Pull request Improve `ComposedSectionProvider` performance on opennetltd/Composed
- Tags:
- open-source
My overall goal here was to measure and then improve all common API usage. This boils down to:
- Appending new sections and section providers
- Inserting new sections and section providers at arbitrary positions
- Reading the section offset for a given section or section provider
The test results are as follows, comparing to ea6375881e2636b253ab1138ab23bbe99cdf4c1a (which we use now). As you can see, everything is faster, with testPerformanceOfAddingManyChildrenWithManyNodesInTree
being much faster now.
| Test | ea6375881e2636b253ab1138ab23bbe99cdf4c1a | Now |
|------|-------|-----|
| testPerformanceOfFindingLastSectionOffset
| 0.0000322 s | 0.00000792 s |
| testPerformanceOfFindingLastSectionProviderOffset
| 0.00105 s | 0.000683 s |
| testPerformanceOfFindingSectionProviderBeforeLastOffset
| 0.0000326 s | 0.0000118 s |
| testPerformanceOfFindingSectionBeforeLastOffset
| 0.00107 s | 0.000712 s |
| testPerformanceOfAddingManyChildrenWithManyNodesInTree
| 21.3 s | 0.0668 s |
| testPerformanceOfAddingManyChildrenToSingleComposedSectionProvider
| 0.000196 s | 0.000115 s |
Note that this is testing some specific hot paths (namely appending) and the non-hot-paths.
Also note that these are extreme tests; we end up with over 19,500 total sections. The most I've seen in the app is more like 700-800.
There are a few different things contributing to this speed up:
- [x] Removal of
AggregateSectionProvider
.- This is mostly an issue when the client app is freshly launched and has a lot of conformances. It's always nice to avoid a conformance check though.
- [x] The
ComposedSectionProvider
now sends itself as theprovider
for delegate calls- This means that all the section offset mapping is done for direct descendants, which we can create an optimised path for.
- [x]
ComposedSectionProvider.providers
is no longer computed, so lookups are much faster. - [ ] Fully remove
SectionProviderMapping
.- This was trying to cache various lookups but really it was just contributing to some of the slow downs because it was trying to create a top-level cache of offsets. We can rely on
ComposedSectionProvider
directly now for this.
- This was trying to cache various lookups but really it was just contributing to some of the slow downs because it was trying to create a top-level cache of offsets. We can rely on
- [ ] Apply the same optimisations to
FlatSection
- I would say this is out of scope for this PR.