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

Improve performance of JSON import and add progress bar #7654

Merged

Conversation

scottbell
Copy link
Contributor

@scottbell scottbell commented Mar 29, 2024

Closes #7612

Describe your changes:

Instead of using JSON.parse, JSON.stringify, and Regex, walk the tree instead. This speeds up the import considerably. I also added a progress bar so the user can see the status of the import.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Is this a notable change that will require a special callout in the release notes? For example, will this break compatibility with existing APIs or projects that consume these plugins?

Author Checklist

  • Changes address original issue?
  • Tests included and/or updated with changes?
  • Has this been smoke tested?
  • Have you associated this PR with a type: label? Note: this is not necessarily the same as the original issue.
  • Have you associated a milestone with this PR? Note: leave blank if unsure.
  • Testing instructions included in associated issue OR is this a dependency/testcase change?

Reviewer Checklist

  • Changes appear to address issue?
  • Reviewer has tested changes by following the provided instructions?
  • Changes appear not to be breaking changes?
  • Appropriate automated tests included?
  • Code style and in-line documentation are appropriate?

@scottbell scottbell linked an issue Mar 29, 2024 that may be closed by this pull request
7 tasks
@scottbell
Copy link
Contributor Author

With this export (Big Test Folder (2).json.zip), the speed goes from > 5 minutes, to a few seconds:

Screen.Recording.2024-03-29.at.4.27.54.PM.mov

@scottbell scottbell requested review from ozyx and akhenry March 29, 2024 15:30
@scottbell scottbell added type:enhancement performance impacts or improves performance labels Mar 29, 2024
@scottbell scottbell added this to the Target:4.0.1 milestone Mar 29, 2024
@@ -123,8 +122,6 @@ describe('The import JSON action', function () {
Object.prototype.hasOwnProperty.call(newObject, '__proto__') ||
Object.prototype.hasOwnProperty.call(Object.getPrototypeOf(newObject), 'toString');

// warning from openmct.objects.get
expect(console.warn).not.toHaveBeenCalled();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

vue warnings were causing tests to fail here

@scottbell scottbell marked this pull request as ready for review March 29, 2024 16:29
@scottbell scottbell added the pr:e2e:couchdb npm run test:e2e:couchdb label Mar 29, 2024
@codecov-commenter
Copy link

codecov-commenter commented Mar 29, 2024

Codecov Report

Attention: Patch coverage is 91.17647% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 54.78%. Comparing base (6c5b925) to head (0daa8ae).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7654      +/-   ##
==========================================
- Coverage   54.95%   54.78%   -0.17%     
==========================================
  Files         430      672     +242     
  Lines       13469    27183   +13714     
  Branches        0     2634    +2634     
==========================================
+ Hits         7402    14893    +7491     
- Misses       6067    11962    +5895     
- Partials        0      328     +328     
Flag Coverage Δ
e2e-full ?
e2e-stable 52.99% <0.00%> (-1.87%) ⬇️
unit 49.19% <91.17%> (?)
Files Coverage Δ
...ugins/importFromJSONAction/ImportFromJSONAction.js 75.83% <91.17%> (+59.99%) ⬆️

... and 394 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c5b925...0daa8ae. Read the comment docs.

@github-actions github-actions bot removed the pr:e2e:couchdb npm run test:e2e:couchdb label Mar 29, 2024
Copy link
Member

@ozyx ozyx left a comment

Choose a reason for hiding this comment

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

Nice work, this is awesome! I've got some comments-- nothing blocking but some readability improvements and other nitpicks before we merge

src/plugins/importFromJSONAction/ImportFromJSONAction.js Outdated Show resolved Hide resolved
src/plugins/importFromJSONAction/ImportFromJSONAction.js Outdated Show resolved Hide resolved
src/plugins/importFromJSONAction/ImportFromJSONAction.js Outdated Show resolved Hide resolved
src/plugins/importFromJSONAction/ImportFromJSONAction.js Outdated Show resolved Hide resolved
src/plugins/importFromJSONAction/ImportFromJSONAction.js Outdated Show resolved Hide resolved
@@ -170,9 +276,16 @@ export default class ImportAsJSONAction {
* @param {Object} objTree
*/
async _importObjectTree(domainObject, objTree) {
Copy link
Member

Choose a reason for hiding this comment

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

can we switch these to actual private methods without ruining the unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing these to private methods cause issues with the way we're returning from _showForm. E.g., changing to #importObjectTree causes:

ImportFromJSONAction.js:77 Uncaught (in promise) TypeError: Receiver must be an instance of class ImportAsJSONAction
    at ImportAsJSONAction.onSave (ImportFromJSONAction.js:77:1)
    at eval (ImportFromJSONAction.js:376:1)

@scottbell scottbell requested a review from ozyx April 1, 2024 11:08
@scottbell scottbell added the pr:e2e:couchdb npm run test:e2e:couchdb label Apr 1, 2024
@github-actions github-actions bot removed the pr:e2e:couchdb npm run test:e2e:couchdb label Apr 1, 2024
Copy link
Member

@ozyx ozyx left a comment

Choose a reason for hiding this comment

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

LGTM

@ozyx ozyx enabled auto-merge (squash) April 16, 2024 21:12
@ozyx ozyx added the pr:e2e:couchdb npm run test:e2e:couchdb label Apr 16, 2024
@github-actions github-actions bot removed the pr:e2e:couchdb npm run test:e2e:couchdb label Apr 16, 2024
@ozyx ozyx merged commit ef8b353 into master Apr 16, 2024
19 checks passed
@ozyx ozyx deleted the 7612-import-from-json-is-extremely-slow-with-large-imports branch April 16, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance impacts or improves performance type:enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import from JSON is extremely slow with large imports
3 participants