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

tools: refactor js2c.cc to use c++20 #54849

Merged
merged 12 commits into from
Sep 19, 2024

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Sep 8, 2024

Refactors js2c.cc to use modern syntax.

@nodejs-github-bot nodejs-github-bot added the tools Issues and PRs related to the tools directory. label Sep 8, 2024
@anonrig anonrig requested a review from jasnell September 8, 2024 16:12
@RedYetiDev RedYetiDev added the c++ Issues and PRs that require attention from people who are familiar with C++. label Sep 8, 2024
@lemire
Copy link
Member

lemire commented Sep 8, 2024

@anonrig Let me check.

tools/js2c.cc Show resolved Hide resolved
@lemire
Copy link
Member

lemire commented Sep 8, 2024

@anonrig Please see anonrig#14

@anonrig
Copy link
Member Author

anonrig commented Sep 8, 2024

@anonrig Please see anonrig#14

amazing work as always @lemire

Co-authored-by: Daniel Lemire <[email protected]>
tools/js2c.cc Outdated Show resolved Hide resolved
Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

Generally LGTM with nits.

tools/js2c.cc Outdated Show resolved Hide resolved
Co-authored-by: Daniel Lemire <[email protected]>
tools/js2c.cc Outdated Show resolved Hide resolved
@lemire
Copy link
Member

lemire commented Sep 8, 2024

@anonrig I did not lint my changes. :-)

@anonrig
Copy link
Member Author

anonrig commented Sep 8, 2024

@lemire it seems windows build is failing. any idea?

@jasnell
Copy link
Member

jasnell commented Sep 8, 2024

D:\a\node\node\out\Release\obj\global_intermediate\node_javascript.cc(12,1): error C1064: compiler limit: token overflowed internal buffer [D:\a\node\node\libnode.vcxproj]
  (compiling source file '/out/Release//obj/global_intermediate/node_javascript.cc')

"An identifier exceeds the length of the internal buffer used for identifiers. Shorten the name."

That's a new one for me. I don't know if this is actually the failure but spotted it in the build log.

@lemire
Copy link
Member

lemire commented Sep 8, 2024

@jasnell @anonrig

"An identifier exceeds the length of the internal buffer used for identifiers. Shorten the name."

I am not sure.

@lemire
Copy link
Member

lemire commented Sep 8, 2024

@anonrig @jasnell

I did not try with Visual Studio (yet), but here is the node_javascript.cc file generated on my mac with this PR:

https://gist.github.com/lemire/a8544683cb6fba911a86843cff048e0d

By the look of it, we have a string... a gigantic string spanning thousands of lines. I think that's what Visual Studio does not like, but how (or whether) it relates to this PR, I don't know.

tools/js2c.cc Show resolved Hide resolved
@lemire
Copy link
Member

lemire commented Sep 8, 2024

@anonrig @jasnell

If one of you has quick access to Windows + Node, building this PR and checking what the node_javascript.cc file looks like might help.

It could possibly be an encoding problem... or anything really. Hard to tell. :-/

(I have my Windows laptop, but I have to leave just now.)

@lemire
Copy link
Member

lemire commented Sep 9, 2024

Ok. I think I figured it out.

@targos targos added dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. labels Sep 9, 2024
Copy link
Member

@lemire lemire left a comment

Choose a reason for hiding this comment

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

Please don't merge this yet, I think we can make the table faster.

Copy link
Member

@lemire lemire left a comment

Choose a reason for hiding this comment

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

Nevermind, it is fine.

@anonrig
Copy link
Member Author

anonrig commented Sep 11, 2024

@joyeecheung any concerns with landing this?

@joyeecheung
Copy link
Member

joyeecheung commented Sep 11, 2024

The starts_with/ends_with changes LGTM. For the code table changes, I think it's a bit over-engineering to make the otherwise straigt-forward code this convoluted to save ~40MB for a build that already takes more than 4GB of memory to work (some of the digital oceans machines with 4GB memory and no extra swap space failed a few weeks ago because of this - which happened during building V8 and would not be in parallel to js2c), or to shave off a few ms from a build that takes tens of minutes/hours. But it's not that convoluted currently for me so I am fine with it (#54849 (comment) on the other hand, is definitely over-engineering this IMO).

I would not block it but I don't feel like approving the code-table part either though because I don't see it as an improvement - If it was another way around, say the code was written like this originally and someone sent a PR to simplify it to the current GetCodeTable(), then I would've approved that because I think that would be a readability improvement with a negligible cost for what the build already takes.

@lemire
Copy link
Member

lemire commented Sep 11, 2024

@joyeecheung @anonrig

Just to clarify... the current change with respect to the table is optimized for speed, not memory usage.

If we want to reduce memory usage, we can drop the table and call std::to_chars.

I expect that compared with @joyeecheung's port of this code from JavaScript to C++, this PR won't move the needle performance wise. But it should be a tiny bit faster!!!

💨

@joyeecheung
Copy link
Member

FWIW the primary motivation of the original port (from Python, not JavaScript) was to experiment with compression options other than zlib (zlib had been shown to be too slow in decompression that we reverted snapshot compression to reverse a runtime performance regression). The performance aspect was only a nice-to-have (also here C++ is at least easier to get reviews from compared to Python).

tools/js2c.cc Show resolved Hide resolved
tools/js2c.cc Show resolved Hide resolved
tools/js2c.cc Show resolved Hide resolved
anonrig and others added 3 commits September 11, 2024 13:17
Co-authored-by: Daniel Lemire <[email protected]>
Co-authored-by: Daniel Lemire <[email protected]>
Co-authored-by: Daniel Lemire <[email protected]>
@anonrig anonrig added commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. commit-queue Add this label to land a pull request using GitHub Actions. labels Sep 11, 2024
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Sep 17, 2024
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/54849
✔  Done loading data for nodejs/node/pull/54849
----------------------------------- PR info ------------------------------------
Title      tools: refactor js2c.cc to use c++20 (#54849)
Author     Yagiz Nizipli <[email protected]> (@anonrig)
Branch     anonrig:tools-simplify -> nodejs:main
Labels     c++, tools, commit-queue-squash, dont-land-on-v18.x, dont-land-on-v20.x
Commits    12
 - tools: refactor js2c.cc to use c++20
 - reducing memory usage and making GetCode's buffer potentially evaluat…
 - Update js2c.cc
 - Update js2c.cc
 - lint
 - minor fix
 - Update tools/js2c.cc
 - removing constexpr
 - lint
 - Update tools/js2c.cc
 - Update tools/js2c.cc
 - Update tools/js2c.cc
Committers 3
 - Yagiz Nizipli <[email protected]>
 - GitHub <[email protected]>
 - Daniel Lemire <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/54849
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Lemire <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/54849
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Lemire <[email protected]>
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last approving review:
   ⚠  - Update tools/js2c.cc
   ⚠  - Update tools/js2c.cc
   ⚠  - Update tools/js2c.cc
   ℹ  This PR was created on Sun, 08 Sep 2024 16:08:34 GMT
   ✔  Approvals: 2
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/54849#pullrequestreview-2288589793
   ✔  - Daniel Lemire (@lemire): https://github.com/nodejs/node/pull/54849#pullrequestreview-2297353318
   ✔  Last GitHub CI successful
   ℹ  Green GitHub CI is sufficient
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/10894139953

@anonrig anonrig requested a review from lemire September 19, 2024 19:06
@anonrig anonrig added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Sep 19, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 19, 2024
@nodejs-github-bot nodejs-github-bot merged commit cde6dcc into nodejs:main Sep 19, 2024
31 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in cde6dcc

targos pushed a commit that referenced this pull request Oct 4, 2024
PR-URL: #54849
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Lemire <[email protected]>
@aduh95 aduh95 mentioned this pull request Oct 9, 2024
louwers pushed a commit to louwers/node that referenced this pull request Nov 2, 2024
PR-URL: nodejs#54849
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Lemire <[email protected]>
tpoisseau pushed a commit to tpoisseau/node that referenced this pull request Nov 21, 2024
PR-URL: nodejs#54849
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Lemire <[email protected]>
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++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants