Perf improvement - matchTags - locationsAt #8761
Merged
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.
Background
Preset matching is the computational logic that returns a strong type from entity tags.
My research is showing that the core method of this logic (matchTags) is a widely used method in iD, is being executed for majority of entities and the reasons are the following:
drawing:
validator:
Optimizing the performance of this method is impactful task to overall iD performance.
Motivation
According to perf measurements and benchmarking linked bellow, the bottle-neck for this method is currently locationAt method.
I've observed that performing locationsAt is not needed for majority of matchings as the best match does not have locationID dependency.
Change being made
This PR does simple reorganization of matchTag method in such a way that the locationsAt is only executed if needed.
Results
Summary: Improved matchTags perf dramatically, and therefore reduces scripting time by ~30%
[edit: For densely populated areas, overall rendering response and scripting is more than x2 faster. Benchmark test here]
As benchmark test I did the following:
Start perf recording
End perf recording
The results are the following:
Before:
Total start-end recording time: 80s
dom rendering: 7s
scripting: 67s out of which:
-- 30s - this.locationsAt
-- 12s - matchScore and others
After (with this change):
Total start-end recording : 60s
scripting: 42s out of which:
--15s - matchScore and others
Moving forward:
Notice the iD v2.19.6 results:
Total start-end recording time: 40s
dom rendering: 7s
scripting: 30s out of which:
- 4s - _this.matchTags
Why is this version of iD matchTags even faster?
The answer is twofold:
Room for improvement:
It is very interesting hypothesis (and an amazing engineering problem :)) that the speed of preset matching logic can be further improved. Currently for a Shop entity, for each tag, code is doing matching with each possible strong type for that geometry type. e.g. point + amenity tag has >5k matchings to do. I will raise a brainstorming issue on this topic.
closes #8612