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

doc, lib, test: do not re-require needlessly #14244

Closed
wants to merge 3 commits into from
Closed

doc, lib, test: do not re-require needlessly #14244

wants to merge 3 commits into from

Conversation

vsemozhetbyt
Copy link
Contributor

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc, lib, test

While cached, re-requiring still has some overhead. So I've checked various patterns prone to re-requiring and tried to reduce it.

Lazy loadings are not touched: if there is a chance that a module may not be required at all, potential re-requiring is left as is.

I have a doubt concerning pummel\test-vm-memleak.js: if it tests leaking in require among other leaks, let me know to revert; otherwise the pummelling can be reduced a bit this way.

@nodejs-github-bot nodejs-github-bot added process Issues and PRs related to the process subsystem. repl Issues and PRs related to the REPL subsystem. tls Issues and PRs related to the tls subsystem. labels Jul 15, 2017
@vsemozhetbyt vsemozhetbyt added doc Issues and PRs related to the documentations. test Issues and PRs related to the tests. labels Jul 15, 2017
@vsemozhetbyt
Copy link
Contributor Author

@@ -1,6 +1,8 @@
'use strict';

const errors = require('internal/errors');
const util = require('util');
Copy link
Member

Choose a reason for hiding this comment

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

It seems that the intention in this file was to do this require only when really needed so I'm not sure if it's a good idea to require it unconditionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've checked this. If I don't miss something, this module is required only in the bootstrap_node.js and the function which requires util is called there unconditionally.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, thanks.

@@ -22,13 +22,16 @@
'use strict';
const common = require('../common');
const assert = require('assert');
let spawn;
Copy link
Member

Choose a reason for hiding this comment

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

I honestly find the original easier in this case, no changes required imho.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

@@ -26,10 +26,10 @@ const fs = require('fs');
const assert = require('assert');
const os = require('os');
const child_process = require('child_process');
const execSync = child_process.execSync;
Copy link
Member

Choose a reason for hiding this comment

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

could this be made like..

const { execSync, spawn } = require('child_process');

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done for all four methods.

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Jul 17, 2017

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Jul 20, 2017

Rebased. CI: https://ci.nodejs.org/job/node-test-pull-request/9265/ (green).

@vsemozhetbyt
Copy link
Contributor Author

Landed in 4f87522

@vsemozhetbyt vsemozhetbyt deleted the no-re-require branch July 21, 2017 17:43
vsemozhetbyt added a commit that referenced this pull request Jul 21, 2017
@addaleax
Copy link
Member

This doesn’t land cleanly on 8.x; if you can, please follow the guide and raise a backport PR, if you don’t think it’s worth it let me know/add the dont-land-on label.

@vsemozhetbyt
Copy link
Contributor Author

8.x backport: #14524

addaleax pushed a commit that referenced this pull request Jul 28, 2017
Backport-PR-URL: #14524
Backport-Reviewed-By: Anna Henningsen <[email protected]>

PR-URL: #14244
Reviewed-By: Alexey Orlenko <[email protected]>
@addaleax addaleax mentioned this pull request Aug 2, 2017
@MylesBorins
Copy link
Contributor

v6.x backport please 😄

@vsemozhetbyt
Copy link
Contributor Author

@MylesBorins
Backport PR: #14876

MylesBorins pushed a commit that referenced this pull request Sep 19, 2017
@MylesBorins MylesBorins mentioned this pull request Sep 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. process Issues and PRs related to the process subsystem. repl Issues and PRs related to the REPL subsystem. test Issues and PRs related to the tests. tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants