Skip to content
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

Replace lodash template with static react renderer for discover's row formatter #98072

Merged
merged 4 commits into from
Apr 28, 2021

Conversation

legrego
Copy link
Member

@legrego legrego commented Apr 22, 2021

Summary

Replaces the rendering logic for Discover's row_formatter. Previous implementation uses lodash.template, which requires unsafe code execution (unsafe-eval in CSP parlance). New implementation uses ReactDOM to render static markup.

This is a prerequisite for hardening our content security policy.

Related: #94626

@legrego legrego added release_note:skip Skip the PR/issue when compiling release notes v7.14.0 v8.0.0 labels Apr 23, 2021
@legrego legrego marked this pull request as ready for review April 23, 2021 13:19
@legrego legrego requested a review from a team April 23, 2021 13:19
@legrego legrego added the auto-backport Deprecated - use backport:version if exact versions are needed label Apr 23, 2021
@kertal
Copy link
Member

kertal commented Apr 26, 2021

@elasticmachine merge upstream ACK will have a look today

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Code LGTM, 👍 . dangerouslySetInnerHTML is safe here due to the use of field formatters. There is one regression here, performance. so the new implementation needs about double of the time to execute.

Old: 2.72 ms in this case
Bildschirmfoto 2021-04-26 um 13 00 11
New: 5.15 ms in this case
Bildschirmfoto 2021-04-26 um 13 03 25
This sums up when there are multiple rows rendered. However I don't think this is a blocker, since we recently switched Discover to the use of #89264 , so it's just used by the legacy table. Do you agree dear @timroes ?

@timroes
Copy link
Contributor

timroes commented Apr 27, 2021

@kertal I would consider this to be fine (also security outwins performance anyway). I am also not sure if in this very fast are we can really rely on the "ratio" between those numbers or if there might be too much variation in it. If we can quickly look into the react performance and figure there's an easy win (not sure how often that's rendered, maybe React.memo will help us here) we can still make it, but I am also fine merging it as it is.

@kertal
Copy link
Member

kertal commented Apr 27, 2021

@kertal I would consider this to be fine (also security outwins performance anyway). I am also not sure if in this very fast are we can really rely on the "ratio" between those numbers or if there might be too much variation in it. If we can quickly look into the react performance and figure there's an easy win (not sure how often that's rendered, maybe React.memo will help us here) we can still make it, but I am also fine merging it as it is.

about the variation, tested in with multiple docs also, generally, performance regression is about the same

@legrego
Copy link
Member Author

legrego commented Apr 27, 2021

Sounds like the performance impact is tolerable then - thanks for verifying! Would be great to get an official approval whenever y'all get the chance - this isn't a huge priority, I just don't want to forget about it

@legrego
Copy link
Member Author

legrego commented Apr 27, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 410.9KB 411.7KB +747.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
discover 74.6KB 74.7KB +74.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kertal
Copy link
Member

kertal commented Apr 28, 2021

If we can quickly look into the react performance and figure there's an easy win (not sure how often that's rendered, maybe React.memo will help us here) we can still make it, but I am also fine merging it as it is.

In this case React.memo won't help, it's rendered in every row, and usually docs are are not equal unless you've got a set of duplicate docs (but also then you would have to check it with isEqual), so I'll plead for merging it as it is. security > performance in this case

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Code LGTM 👍 , didn't test again, but there were no changes to my first test. The performance regression is acceptable, security > performance in this case!

@legrego legrego merged commit 5560802 into elastic:master Apr 28, 2021
@legrego legrego deleted the discover-row-formatter-template branch April 28, 2021 12:33
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Apr 28, 2021
… formatter (elastic#98072)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Apr 28, 2021
… formatter (#98072) (#98600)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Larry Gregory <larry.gregory@elastic.co>
@kertal kertal added the Feature:Discover Discover Application label Apr 29, 2021
madirey pushed a commit to madirey/kibana that referenced this pull request May 11, 2021
… formatter (elastic#98072)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants