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: Improve install performance #23175

Closed
noahtallen opened this issue Jun 15, 2020 · 1 comment · Fixed by #23806
Closed

Env: Improve install performance #23175

noahtallen opened this issue Jun 15, 2020 · 1 comment · Fixed by #23806
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Tool] Env /packages/env [Type] Performance Related to performance efforts

Comments

@noahtallen
Copy link
Member

Is your feature request related to a problem? Please describe.
Look at the install WordPress step of wp-env start:

async function configureWordPress( environment, config ) {
const options = {
config: config.dockerComposeConfigPath,
commandOptions: [ '--rm' ],
log: config.debug,
};
const port = environment === 'development' ? config.port : config.testsPort;
// Install WordPress.
await dockerCompose.run(
environment === 'development' ? 'cli' : 'tests-cli',
[
'wp',
'core',
'install',
`--url=localhost:${ port }`,
`--title=${ config.name }`,
'--admin_user=admin',
'--admin_password=password',
'[email protected]',
'--skip-email',
],
options
);
// Set wp-config.php values.
for ( let [ key, value ] of Object.entries( config.config ) ) {
// Ensure correct port setting from config when configure WP urls.
if ( key === 'WP_SITEURL' || key === 'WP_HOME' ) {
const url = new URL( value );
url.port = port;
value = url.toString();
}
const command = [ 'wp', 'config', 'set', key, value ];
if ( typeof value !== 'string' ) {
command.push( '--raw' );
}
await dockerCompose.run(
environment === 'development' ? 'cli' : 'tests-cli',
command,
options
);
}
// Activate all plugins.
for ( const pluginSource of config.pluginSources ) {
await dockerCompose.run(
environment === 'development' ? 'cli' : 'tests-cli',
`wp plugin activate ${ pluginSource.basename }`,
options
);
}
// Activate the first theme.
const [ themeSource ] = config.themeSources;
if ( themeSource ) {
await dockerCompose.run(
environment === 'development' ? 'cli' : 'tests-cli',
`wp theme activate ${ themeSource.basename }`,
options
);
}
// Since wp-phpunit loads wp-settings.php at the end of its wp-config.php
// file, we need to avoid loading it too early in our own wp-config.php. If
// we load it too early, then some things (like MULTISITE) will be defined
// before wp-phpunit has a chance to configure them. To avoid this, create a
// copy of wp-config.php for phpunit which doesn't require wp-settings.php.
await dockerCompose.exec(
environment === 'development' ? 'wordpress' : 'tests-wordpress',
[
'sh',
'-c',
'sed "/^require.*wp-settings.php/d" /var/www/html/wp-config.php > /var/www/html/phpunit-wp-config.php',
],
{
config: config.dockerComposeConfigPath,
log: config.debug,
}
);

There are two issues here:

  1. We use rm on the docker run command, which means we start and stop the service for each command.
  2. We run each WP command in a separate service run. For example, if you set 10 wp-config values, you'll start and stop the container 10 times.

As you can imagine, this has a big performance overhead.

Describe the solution you'd like

I tested some changes to this which decreased wp-env start from >30s to <10s. Essentially, we can join most of these commands together into one run command. This is how it would look in plain bash as an example; we'd just generate it in JS:

# Before:
docker-compose run cli wp config set THING1 foo1
docker-compose run cli wp config set THING2 foo2
docker-compose run cli wp config set THING3 foo3

# After
docker-compose run cli bash -c "wp config set THING1 foo1 && wp config set THING2 foo2 && wp config set THING3 foo3"

On top of that, we can remove the rm option for many of these commands, since there is no need to stop the service until we are done running everything.

The only challenge I noticed while testing this is that we may need to run the install portion of the script separately from the other commands. Otherwise, it seems to error out.

Describe alternatives you've considered
Echo each wp-config value into the PHP file manually without going through wp-cil. (does not seem like a good idea)

cc @epiqueras

@noahtallen noahtallen added [Type] Performance Related to performance efforts [Tool] Env /packages/env labels Jun 15, 2020
@epiqueras
Copy link
Contributor

Nice, let's do it.

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Tool] Env /packages/env [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants