Skip to content

[EuiIcon] Improve data URI type performance#5751

Merged
thompsongl merged 6 commits intoelastic:mainfrom
thompsongl:5741-icon
Mar 29, 2022
Merged

[EuiIcon] Improve data URI type performance#5751
thompsongl merged 6 commits intoelastic:mainfrom
thompsongl:5741-icon

Conversation

@thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Mar 29, 2022

Summary

Closes #5741

Running an "ends with" regex on a large string (such as a image data URI) takes a long time

Before

Screen Shot 2022-03-29 at 10 42 01 AM




So using alternative string search methods help immensely

After

Screen Shot 2022-03-29 at 10 43 13 AM

We could use indexOf instead of endsWith, but there's extra logic involved to prevent -1 matches. We're using the fastest method to bypass additional parsing of data URIs so I'm less concerned with perf after that point. endsWith provides a good bump compared to the regex (.1ms vs 2ms for URL strings).

Also added a data URI example to the docs.

Checklist

  • Checked in Chrome, Safari, Edge, and Firefox
  • Added documentation
  • Checked Code Sandbox works for any docs examples
  • Checked for breaking changes and labeled appropriately
  • A changelog entry exists and is marked appropriately

@thompsongl thompsongl requested a review from cee-chen March 29, 2022 18:02
@thompsongl thompsongl requested a review from cee-chen March 29, 2022 18:33
Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional / can be done in a follow-up PR] it would be awesome to write a quick set of unit tests (should be 4-5 cases?) for the new util, but only if we have time / are waiting around for the Kibana PR to merge! if not we can add it in a follow-up PR

@thompsongl thompsongl enabled auto-merge (squash) March 29, 2022 18:53
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5751/

@thompsongl thompsongl merged commit d213cc4 into elastic:main Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[EuiIcon] Custom SVG slows down the rendering

3 participants