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

lib: reduce url getters on makeRequireFunction #48492

Merged
merged 1 commit into from
Jun 24, 2023

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Jun 18, 2023

Reduce calling getters of URL due to the lazy loading of URL.

Ref: nodejs/performance#92

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/modules

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jun 18, 2023
Copy link
Member

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

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

Thank you for this!

I gather from this and related PRs that URL objects in general are more costly than primitive strings? Should we make an effort to try to scrub the modules code of URL objects whenever possible, converting to strings instead?

@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jun 20, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 20, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@anonrig
Copy link
Member Author

anonrig commented Jun 21, 2023

Thank you for this!

I gather from this and related PRs that URL objects in general are more costly than primitive strings? Should we make an effort to try to scrub the modules code of URL objects whenever possible, converting to strings instead?

@GeoffreyBooth URL object is not costly, but accessing their attributes except href is costly. For example, calling url.protocol multiple times, will create multiple different strings, rather than the same one. This is caused by the lazy getters of the class. I'm currently trying to reduce URL initializations and multiple getters of the same URL instance across the loaders.

@GeoffreyBooth
Copy link
Member

For example, calling url.protocol multiple times, will create multiple different strings, rather than the same one.

I would think it should be possible to “cache” protocol in whatever way that href is currently stored? So that calling protocol repeatedly is no more costly than calling href, assuming the latter is “inexpensive” (in the sense that it’s not worth trying to refactor to something even simpler).

@anonrig
Copy link
Member Author

anonrig commented Jun 21, 2023

I would think it should be possible to “cache” protocol in whatever way that href is currently stored? So that calling protocol repeatedly is no more costly than calling href, assuming the latter is “inexpensive” (in the sense that it’s not worth trying to refactor to something even simpler).

This might be an (micro)-optimization worth investigating for, but adding a branch and accessing the cache parameter overhead might be greater than just simply reduce calling it. I simply don't have the data right now to back the claim if one approach is better than another.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@anonrig
Copy link
Member Author

anonrig commented Jun 23, 2023

Rebased and force-pushed.

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 23, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 23, 2023
@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 24, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 24, 2023
@nodejs-github-bot nodejs-github-bot merged commit 578ffe1 into nodejs:main Jun 24, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 578ffe1

RafaelGSS pushed a commit that referenced this pull request Jul 3, 2023
PR-URL: #48492
Refs: nodejs/performance#92
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@RafaelGSS RafaelGSS mentioned this pull request Jul 3, 2023
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48492
Refs: nodejs/performance#92
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48492
Refs: nodejs/performance#92
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
ruyadorno pushed a commit that referenced this pull request Sep 10, 2023
PR-URL: #48492
Refs: nodejs/performance#92
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@ruyadorno ruyadorno mentioned this pull request Sep 10, 2023
ruyadorno pushed a commit that referenced this pull request Sep 13, 2023
PR-URL: #48492
Refs: nodejs/performance#92
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants