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

src: use a std::vector for preload_modules #12241

Closed

Conversation

sam-github
Copy link
Contributor

A dynamically allocated array was being used, simplify the memory
management by using std::vector.

Factored out of #12028, its unrelated and easily backportable.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows [commit guidelines][]
Affected core subsystem(s)

src

A dynamically allocated array was being used, simplify the memory
management by using std::vector.
@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Apr 5, 2017
@sam-github
Copy link
Contributor Author

@mscdex mscdex added the module Issues and PRs related to the module subsystem. label Apr 5, 2017
Copy link

@kkoopa kkoopa left a comment

Choose a reason for hiding this comment

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

Left some minor comments which likely have no actual performance impact.

Local<Array> array = Array::New(env->isolate());
for (unsigned int i = 0; i < preload_module_count; ++i) {
for (unsigned int i = 0; i < preload_modules.size(); ++i) {
Copy link

Choose a reason for hiding this comment

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

A do-while loop would avoid one unnecessary bounds check. There is at least one element in the vector.

@@ -3717,7 +3711,7 @@ static void ParseArgs(int* argc,
exit(9);
}
args_consumed += 1;
local_preload_modules[preload_module_count++] = module;
preload_modules.push_back(module);
Copy link

Choose a reason for hiding this comment

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

It should be possible to reserve space in the vector before inserting elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How? This is only inserting one element, I don't know how many -r options were passed.

@sam-github
Copy link
Contributor Author

@kkoopa I appreciate the feedback, but I think readability and minimization of the diff outweights the cost of one additional integer comparison, which is anyhow dwarfed by the cost of actually requiring the module(s).

@kkoopa
Copy link

kkoopa commented Apr 6, 2017 via email

@kkoopa
Copy link

kkoopa commented Apr 6, 2017 via email

@addaleax
Copy link
Member

Landed in cecdf7c

@addaleax addaleax closed this Apr 10, 2017
addaleax pushed a commit that referenced this pull request Apr 10, 2017
A dynamically allocated array was being used, simplify the memory
management by using std::vector.

PR-URL: #12241
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@italoacasas
Copy link
Contributor

cc @sam-github

@sam-github sam-github deleted the use-vector-for-preload-modules branch April 11, 2017 03:41
sam-github added a commit to sam-github/node that referenced this pull request May 18, 2017
A dynamically allocated array was being used, simplify the memory
management by using std::vector.

PR-URL: nodejs#12241
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@jasnell jasnell mentioned this pull request May 11, 2017
@gibfahn
Copy link
Member

gibfahn commented Jun 18, 2017

Backport PR: #12677

sam-github added a commit to sam-github/node that referenced this pull request Oct 11, 2017
A dynamically allocated array was being used, simplify the memory
management by using std::vector.

PR-URL: nodejs#12241
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
MylesBorins pushed a commit that referenced this pull request Oct 16, 2017
A dynamically allocated array was being used, simplify the memory
management by using std::vector.

Backport-PR-URL: #12677
PR-URL: #12241
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Oct 17, 2017
MylesBorins pushed a commit that referenced this pull request Oct 25, 2017
A dynamically allocated array was being used, simplify the memory
management by using std::vector.

Backport-PR-URL: #12677
PR-URL: #12241
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Nov 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. module Issues and PRs related to the module subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.