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

[Console] Fix performance bottleneck for large JSON payloads #57668

Merged

Conversation

jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Feb 14, 2020

Summary

Fix #57431

Notes for reviewers

The bulk of changes are whitespace changes 🤦🏼‍♂️ for a test file that was updated to check line count number is reporting correctly.

The rest should be in legacy_core_editor.ts, sense_editor.ts and token_provider.ts. Specifically we are now using .getLength that returns a cached value of the line count.

https://github.com/ajaxorg/ace/blob/d35142c47b5549ab5714848f373b98a4462d2bdd/lib/ace/edit_session.js#L1092

How to test

See the original issues for details. Thanks @LucaWintergerst for reporting!

Also attempt to edit text at the bottom of the large body. This will cause the autocomplete token iterator to traverse a large part of the body.

There should now be no noticeable delay when typing or moving the cursor around.

Release Note

We fixed a Console performance regression that caused a big slow down for large request bodies.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

The legacy_core_editor implemenation was calculating the current editor line
count by .split('\n').length on the entire buffer which was very inefficient
in a tight loop. This caused a performance regression. Now we use the cached
line count provided by the underlying editor implementation.
Probably was not a performance issue, just taking unnecessary steps. Not
sure that this function is even being used.
@jloleysens jloleysens added Feature:Console Dev Tools Console Feature Feature:Dev Tools release_note:fix v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.7.0 v7.6.1 labels Feb 14, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

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

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

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

LGTM! Tested locally and works great with the large body.
Left a comment about var naming that help to enter the context of console 😊


function tokenTest(tokenList, prefix, data) {
if (data && typeof data !== 'string') {
data = JSON.stringify(data, null, 3);
Copy link
Contributor

Choose a reason for hiding this comment

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

3? really? 😊

position: { lineNumber: 1, column: 1 },
});
const ret = [];
let t = iter.getCurrentToken();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: let token = ...

editor: coreEditor,
position: { lineNumber: 1, column: 1 },
});
const ret = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to name it? what exactly do we expect to return?

@jloleysens
Copy link
Contributor Author

@sebelga Thanks for the review! Currently those tests are all really old and not super friendly to new readers. I plan on revisiting them all when we start this work: #57435

@jloleysens jloleysens merged commit 7f71c78 into elastic:master Feb 14, 2020
@jloleysens jloleysens deleted the fix/console/performance-bottleneck branch February 14, 2020 12:56
jloleysens added a commit to jloleysens/kibana that referenced this pull request Feb 14, 2020
…#57668)

* Fix Console performance bug for large request bodies

The legacy_core_editor implemenation was calculating the current editor line
count by .split('\n').length on the entire buffer which was very inefficient
in a tight loop. This caused a performance regression. Now we use the cached
line count provided by the underlying editor implementation.

* Fix performance regression inside of ace token_provider implementation

* Clean up another unnecessary use of getValue().split(..).length.

Probably was not a performance issue, just taking unnecessary steps. Not
sure that this function is even being used.
jloleysens added a commit to jloleysens/kibana that referenced this pull request Feb 14, 2020
…#57668)

* Fix Console performance bug for large request bodies

The legacy_core_editor implemenation was calculating the current editor line
count by .split('\n').length on the entire buffer which was very inefficient
in a tight loop. This caused a performance regression. Now we use the cached
line count provided by the underlying editor implementation.

* Fix performance regression inside of ace token_provider implementation

* Clean up another unnecessary use of getValue().split(..).length.

Probably was not a performance issue, just taking unnecessary steps. Not
sure that this function is even being used.

# Conflicts:
#	src/legacy/core_plugins/console/public/np_ready/application/models/legacy_core_editor/__tests__/input.test.js
#	src/legacy/core_plugins/console/public/np_ready/application/models/legacy_core_editor/__tests__/input_tokenization.test.js
jloleysens added a commit that referenced this pull request Feb 14, 2020
…#57683)

* Fix Console performance bug for large request bodies

The legacy_core_editor implemenation was calculating the current editor line
count by .split('\n').length on the entire buffer which was very inefficient
in a tight loop. This caused a performance regression. Now we use the cached
line count provided by the underlying editor implementation.

* Fix performance regression inside of ace token_provider implementation

* Clean up another unnecessary use of getValue().split(..).length.

Probably was not a performance issue, just taking unnecessary steps. Not
sure that this function is even being used.

# Conflicts:
#	src/legacy/core_plugins/console/public/np_ready/application/models/legacy_core_editor/__tests__/input.test.js
#	src/legacy/core_plugins/console/public/np_ready/application/models/legacy_core_editor/__tests__/input_tokenization.test.js
jloleysens added a commit that referenced this pull request Feb 14, 2020
…#57682)

* Fix Console performance bug for large request bodies

The legacy_core_editor implemenation was calculating the current editor line
count by .split('\n').length on the entire buffer which was very inefficient
in a tight loop. This caused a performance regression. Now we use the cached
line count provided by the underlying editor implementation.

* Fix performance regression inside of ace token_provider implementation

* Clean up another unnecessary use of getValue().split(..).length.

Probably was not a performance issue, just taking unnecessary steps. Not
sure that this function is even being used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Console Dev Tools Console Feature Feature:Dev Tools release_note:fix Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.6.1 v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DevTools Console Freezes when using large JSON blocks
4 participants