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

Env: Only perform expensive install work when required #23809

Merged
merged 5 commits into from
Jul 14, 2020

Conversation

noahtallen
Copy link
Member

@noahtallen noahtallen commented Jul 9, 2020

Description

TLDR: wp-env start only takes 1-2 seconds in common use cases.

wp-env start is now much lazier, only doing time-intensive work when required.

wp-env previously did the following actions on every run:

  • WordPress configuration is applied (e.g. wp core install and wp config set)
  • Download specified remote sources like WordPress
  • Ran wp-env stop as a "restart" mechanism to handle some edge cases

Now, these actions are only performed in two situations:

  1. The parsed wp-env configuration is different. (Configuration is considered different on first install, when updating *.wp-env.json files, and when different environment variables change.)
  2. The user specifies the --update flag.

To accomplish this, I added a little library to read/write cache values to a cache JSON file stored in the wp-env work directory. This might be useful in the future, particularly if we want to get more granular about this behavior.

Note that the WordPress install and source downloads still happen each run so that they stay up-to-date.

How has this been tested?

Locally, in wp-env; CI should work. You can test with npx wp-env start locally with this branch checked out and it will run sourcecode.

Screenshots

The first run is before this change. The second is with this improvement:

Screen Shot 2020-07-08 at 6 20 12 PM

Types of changes

Performance improvement

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@noahtallen noahtallen added [Type] Build Tooling Issues or PRs related to build tooling [Type] Performance Related to performance efforts labels Jul 9, 2020
@noahtallen noahtallen requested a review from epiqueras July 9, 2020 01:58
@noahtallen noahtallen self-assigned this Jul 9, 2020
@github-actions
Copy link

github-actions bot commented Jul 9, 2020

Size Change: +91 B (0%)

Total Size: 1.14 MB

Filename Size Change
build/block-directory/index.js 7.67 kB -1 B
build/block-editor/index.js 115 kB +3 B (0%)
build/block-library/index.js 132 kB +1 B
build/components/index.js 199 kB +97 B (0%)
build/compose/index.js 9.67 kB -2 B (0%)
build/core-data/index.js 11.5 kB -2 B (0%)
build/data/index.js 8.45 kB -1 B
build/edit-navigation/index.js 10.8 kB -2 B (0%)
build/edit-post/index.js 304 kB -3 B (0%)
build/edit-post/style-rtl.css 5.61 kB +7 B (0%)
build/edit-post/style.css 5.61 kB +7 B (0%)
build/edit-site/index.js 16.8 kB -3 B (0%)
build/edit-widgets/index.js 9.35 kB -1 B
build/editor/index.js 45.1 kB -3 B (0%)
build/format-library/index.js 7.72 kB -2 B (0%)
build/list-reusable-blocks/index.js 3.12 kB -1 B
build/media-utils/index.js 5.32 kB -1 B
build/plugins/index.js 2.56 kB -1 B
build/server-side-render/index.js 2.71 kB -2 B (0%)
build/token-list/index.js 1.27 kB +1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 944 B 0 B
build/block-directory/style.css 945 B 0 B
build/block-editor/style-rtl.css 10.8 kB 0 B
build/block-editor/style.css 10.8 kB 0 B
build/block-library/editor-rtl.css 7.6 kB 0 B
build/block-library/editor.css 7.59 kB 0 B
build/block-library/style-rtl.css 7.77 kB 0 B
build/block-library/style.css 7.77 kB 0 B
build/block-library/theme-rtl.css 728 B 0 B
build/block-library/theme.css 729 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.2 kB 0 B
build/components/style-rtl.css 15.9 kB 0 B
build/components/style.css 15.8 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/dom/index.js 3.23 kB 0 B
build/edit-navigation/style-rtl.css 1.08 kB 0 B
build/edit-navigation/style.css 1.08 kB 0 B
build/edit-site/style-rtl.css 3.04 kB 0 B
build/edit-site/style.css 3.04 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/editor/style-rtl.css 3.78 kB 0 B
build/editor/style.css 3.78 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 709 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/primitives/index.js 1.4 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@noahtallen noahtallen force-pushed the try/avoid-wp-install-when-unneeded branch from d50ba1e to 5e2ab85 Compare July 9, 2020 17:35
@noahtallen
Copy link
Member Author

@epiqueras do you know if we need run the WordPress configuration code again if the WordPress source updates? Currently, if it does a git pull (or whatever) on the WordPress source, it will not run install/configuration again. (it only does that if the config is new to your system or has changed)

@noahtallen noahtallen added the [Tool] Env /packages/env label Jul 9, 2020
@epiqueras
Copy link
Contributor

I guess it depends on the nature of the changes that have been pulled in.

@noahtallen
Copy link
Member Author

Hm. What if:

  1. We only download updates to sources if the config changes (e.g. same logic we have now)
  2. We add a flag to download updates to sources (like wp-env start --update) which also re-configures wp.

@epiqueras
Copy link
Contributor

That makes more sense. People might not want to update sometimes too.

@noahtallen
Copy link
Member Author

Makes sense. Added in c36e22d.

Copy link
Contributor

@jeyip jeyip left a comment

Choose a reason for hiding this comment

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

Spent a good amount of time wrapping my head around the wp-env package. Definitely not an expert, but the caching logic looks reasonable.

I can also confirm that:

  • the cache is busted when .wp-env.json options change
  • the performance is blazing fast 🔥

I'm having trouble verifying that adding the --update flag busts the cache though.

@noahtallen
Copy link
Member Author

I'm having trouble verifying that adding the --update flag busts the cache though.

if it takes > 2 seconds then it should be re-configuring wp. In Gutenberg, you can also verify by noting that it shows "downloading WordPress" for a brief moment before continuing (if it is already up to date)

Copy link
Contributor

@jeyip jeyip left a comment

Choose a reason for hiding this comment

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

if it takes > 2 seconds then it should be re-configuring wp. In Gutenberg, you can also verify by noting that it shows "downloading WordPress" for a brief moment before continuing (if it is already up to date)

My mistake. I should clarify. When I said "I'm having trouble verifying", I meant that I wasn't able to force the longer load times. Passing the --update flag didn't lead to expected behavior.

@noahtallen
Copy link
Member Author

@jeyip oh, interesting! Here's a gif of what it does for me:

2020-07-13 10 34 04

@jeyip
Copy link
Contributor

jeyip commented Jul 13, 2020

@noahtallen Let me try again. I'll keep you updated.

@jeyip
Copy link
Contributor

jeyip commented Jul 13, 2020

  • npm run wp-env start --update looks like it references the cache
  • npx wp-env start --update looks like it forces the reconfiguration

npm run
npx

@noahtallen
Copy link
Member Author

🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔

@noahtallen
Copy link
Member Author

That's confusing, since both should ultimately be accessing ./packages/env/bin/wp-env. And it's even more confusing because both are clearly picking up on some of the cache changes

@noahtallen
Copy link
Member Author

@jeyip I figured it out actually 😅 If you run npm run wp-env --update, the update flag is not passed to wp-env. You have to run npm run wp-env -- --update

Screen Shot 2020-07-13 at 11 19 10 AM

@jeyip
Copy link
Contributor

jeyip commented Jul 13, 2020

Oh I see! Thanks for helping debug that. This seems like user error since npm documents the extra -- pretty clearly. Everything else looks good to me 🎉

- add --update flag to force update
- add cache lib to store config checksum
- only run update if checksum changed
@noahtallen noahtallen force-pushed the try/avoid-wp-install-when-unneeded branch from 7924729 to 9e9606e Compare July 14, 2020 17:57
@noahtallen noahtallen requested a review from epiqueras July 14, 2020 18:12
packages/env/lib/cache.js Outdated Show resolved Hide resolved
packages/env/lib/cache.js Outdated Show resolved Hide resolved
packages/env/lib/cache.js Outdated Show resolved Hide resolved
@noahtallen noahtallen changed the title Env: Only perform intensive install work when required Env: Only perform expensive install work when required Jul 14, 2020
@noahtallen noahtallen merged commit 87be0aa into master Jul 14, 2020
@noahtallen noahtallen deleted the try/avoid-wp-install-when-unneeded branch July 14, 2020 21:04
@github-actions github-actions bot added this to the Gutenberg 8.6 milestone Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] Env /packages/env [Type] Build Tooling Issues or PRs related to build tooling [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants