Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Nov 20, 2021

We were importing these modules in different places and
under different names. I went with fs for the name
of the fs import since that is what library_nodefs.js
and it is by far the heaviest user of this module.

@sbc100 sbc100 force-pushed the unify_node_imports branch 2 times, most recently from d0521a8 to cf23a96 Compare November 20, 2021 17:10
self.assertLess(changed, normal)
# Check an absolute code size as well, with some slack.
self.assertLess(abs(changed - 5001), 150)
self.assertLess(abs(changed - 5174), 150)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The rebase here is actually going from 5150 to 5174 so 24 bytes difference from main

@sbc100 sbc100 requested review from RReverser and kripken November 29, 2021 18:33
@sbc100 sbc100 force-pushed the unify_node_imports branch from cf23a96 to 3f07a44 Compare November 29, 2021 19:02
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Maybe with that comment the code size regression goes away? If not, why is it getting worse? I'd expect closure to inline those calls and end up with similar size as before, unless the issue is that we include both of the modules at each site which we didn't before.

requireNodeFS();
filename = nodePath['normalize'](filename);
nodeFS['readFile'](filename, function(err, data) {
fs.readFile(filename, function(err, data) {
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure the quoting is not needed here? Is closure aware of the Node.js FS API?

Comment on lines 8 to 9
if (!fs) fs = require('fs');
if (!nodePath) nodePath = require('path');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!fs) fs = require('fs');
if (!nodePath) nodePath = require('path');
// We always initialize both of these together, so we can use
// either one as the indicator for them not being initialized.
if (!fs) {
fs = require('fs');
nodePath = require('path');
}

This is I think smaller?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I still see a 19 byte regression in this test (although we have 150 byte tollerance here).

Its due to the function itself being part of the output:

E = function() { fs || (fs = require("fs"), D = require("path")) },

Since this is tiny and will not be present for folks that set ENVIRONMENT=web anyway I think its fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

None of actual code size tests regress even one byte.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, good point that it just affects node-enabled builds.

We were importing these modules in different places and
under different names.  I went with `fs` for the name
of the `fs` import since that is what `library_nodefs.js`
and it is by far the heaviest user of this module.
@sbc100 sbc100 force-pushed the unify_node_imports branch from 3f07a44 to c39723d Compare November 30, 2021 19:10
@sbc100 sbc100 enabled auto-merge (squash) November 30, 2021 19:10
@sbc100 sbc100 merged commit 8a60563 into main Nov 30, 2021
@sbc100 sbc100 deleted the unify_node_imports branch November 30, 2021 20:08
mmarczell-graphisoft pushed a commit to GRAPHISOFT/emscripten that referenced this pull request Jan 5, 2022
We were importing these modules in different places and
under different names.  I went with `fs` for the name
of the `fs` import since that is what `library_nodefs.js`
and it is by far the heaviest user of this module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants