-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Optimize performance of setCategoryIndex #1544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
40e69d3
Optimize performance of setCategoryIndex
hy9be b47c7af
Update unit test
hy9be e8941d6
Refactor the changes
hy9be b3fb03d
Build the lookup map for initialized categories
hy9be 2992126
Reset the lookup map when the categories are reset
hy9be 989f07a
Optimize the scatter trace sorting comparator with map
hy9be 91cfaa4
Merge remote-tracking branch 'origin/master' into perf-setcategoryindex
hy9be abcd729
Clean ESLint errors in CI
hy9be 153f547
getCategoryIndex falls back to the former implementation to fix the f…
hy9be ff043b4
Fix another problem in getCategoryIndex
hy9be c32163e
Add comments
hy9be d2be6c9
Remove the fallback to indexOf search in getCategoryIndex, update the…
hy9be 14d6649
Remove out of date comments
hy9be File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this block is only here to fix that test, and never gets hit in real code (which looks to be the case to me, since
ax._categories
andax._categoriesMap
always get populated simultaneously) then we should leave out theelse
block here, and just make the test more realistic by creating the corresponding_categoriesMap
in the mockax
object.For the record, this made me curious "do we still need
ax._categories
at all?" But you were right to not remove it, asgetCategoryName
(ax.c2d
etc, ie hover info) still needs the reverse mapping to be fast.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree. I will make the change on the mock object instead.
Yeah I tried to completely replacing the
_categories
array with the map, but there will be some cases we need a reverse mapping.Actually, comparing to maintaining a pair of synced-up array and map, I feel there must be some better data structure for a performant categories collection. But I was sort of lazy and did not give it another think anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'm sure there is, though it won't be built in so is unlikely to improve performance, it would just clean up the API... lets not worry about it for now, this two-part solution is light and easy enough to use here but we can look into it further if this comes up in enough other places.