-
Notifications
You must be signed in to change notification settings - Fork 21
Inline host config #30
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: master
Are you sure you want to change the base?
Conversation
Moving all deps to devDeps since they are all resolved during compile time. |
Nice! I'm not sure about about the dependency move, what about all the runtime deps like dom helpers and react. Those are still needed at runtime and probably shouldn't be inlined right? |
As much as I understand, not all (especially the large ones) functions are
inline
…On Sat 16 Jun, 2018, 6:37 PM Jason Quense, ***@***.***> wrote:
Nice! I'm not sure about about the dependency move, what about all the
runtime deps like dom helpers and react. Those are still needed at runtime
and probably shouldn't be inlined right?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#30 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC9BukH7CRr2Zx2qWY2vGmK_VLRki0_gks5t9QMZgaJpZM4UqVWL>
.
|
I think we only want to inline react-reconciler, otherwise the bundle will include React and dom-helpers which will be a big bundle increase for folks since they will have duplicated copies of react, and anyone using dom-helpers will also be duplicated right? |
I think the closure compiler takes a call on what to inline or not. And
only small functions, where perf gains from avoiding extra stack frames are
significant, get inlined.
…On Sat 16 Jun, 2018, 6:55 PM Jason Quense, ***@***.***> wrote:
I think we only want to inline react-reconciler, otherwise the bundle will
include React and dom-helpers which will be a big bundle increase for folks
since they will have duplicated copies of react, and anyone using
dom-helpers will also be duplicated right?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#30 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC9BumBhr5jyhXkCcmRMa6QB35Q1mvwRks5t9QdcgaJpZM4UqVWL>
.
|
841cd67
to
672a0f7
Compare
sure but it will still make the practical bundle size of ppl using RDL bigger if we let it do that. I don't think that's what we want |
I think I misunderstood earlier. You're right. We're on the same page. I have re-introduced other deps back in package.json and marked them external for rollup. |
Inlining was not seen in simple mode
Please compare the build sizes between commit 4a53dec and . This is because previously we didn’t inline npm deps in the cjs bundles. I added Added index.js so that minified bundle is required too. Previously only unminified bundle was a part of package.json's main. Had to use ADVANCED mode for closure compiler. We might have to add build level checks. I had to remove flow defs for the host config too, for the time being. Will revisit tomorrow or so. |
This is pretty hard to get working, I wouldn't recommend. Why do you need it? |
$$hostconfig never got inlined in simple mode. @gaearon |
Hello world app bundled (created using CRA) fell down to 23.76 KB |
It falling down doesn't mean everything works correctly though. I'd be very cautious. If it doesn't get inlined, maybe we can explore something on our side to fix this. |
Sorry. This wasn't meant you justify use of advanced mode. I wanted to report the changes in build size. Probably should have updated my previous comment. You're right about the safety of the build. I did try a couple of things like avoid unnecessary function calls so that gcc can statically analyse hostconfig. Eventually ran out of ideas. |
@gaearon Can you please share some ideas to help inline the host config? My initial attempts were to make sure the object is statically analysable. I could have missed though. |
I couldn't get the following to inline in simple mode :( Tested it on the online tool too function log(m) {
console.log(m);
}
log(m); |
Just reporting it here. Dan is right about GCC - I got bit by GCC's advanced mode in a project I was working on. |
I stand corrected. Figured why GCC didn't inline my code earlier: function main(){
function log(m) {
console.log(m);
}
log('m');
log('m');
log('m');
log('m');
log('m');
log('m');
log('m');
}
main() Inlined code function main() {
console.log("m");
console.log("m");
console.log("m");
console.log("m");
console.log("m");
console.log("m");
console.log("m");
}
main(); |
Reverting the advanced level changes shortly |
a7bc370
to
7f8202f
Compare
I observed the following: a.js (function main() {
const config = {
log(m) {
console.log(m);
}
}
function reconciler(c) {
const log = c.log;
log('jere');
}
reconciler(config);
}()) a.min.js (function() {
(function(a) {
a = a.log;
a("jere");
})({
log: function(a) {
console.log(a);
}
});
})(); b.js (function main() {
const config = {
log(m) {
console.log(m);
}
}
function reconciler(c) {
const log = c.log;
c.log('here');
// log('jere');
}
reconciler(config);
}()) b.min.js (function() {
console.log("here");
})(); |
The transform script moves host config inside the reconciler() to help GCC inline code better
ExplanationTrying to understand GCC's behaviourI tried replicating the bundle's code behaviour of wrapping a config object and tried running GCC on it. I got GCC to inline the following: const config = {
log(m) {
console.log(m);
}
}
function reconciler(c) {
const log = c.log;
c.log('here');
// log('jere');
}
reconciler(config); But not the following which resembles the bundle better const config = {
log(m) {
console.log(m);
}
}
function reconciler(c) {
const log = c.log;
log('jere');
return {
foo() {
// More side effects
}
}
}
reconciler(config); I tried a couple of other variations too. Reported it on SO and Google Groups. Tweeted about it too. Most reliable response was from one of the maintainers of GCC on SO.
Thats when I decided to transform to the structure of our bundle to resemble React DOM's. The babel transformBasically, the scripts transforms, function createInstance() {
}
function appendChild() {
}
const config = {
createInstance: createInstance
appendChild: appendChild
}
function reconciler(config) {
var ax = config.createInstance,
by = config.appendChild;
// ...
}
reconciler(config); to // const config = { ... } is removed
function reconciler(config) {
var ax = function createInstance() {
}
var by = function appendChild() {
}
// ...
}
reconciler({}); GotchasThe transform depends on the line I figure what I am still inspecting both transformed and the inlined code (using the newly added debug mode in GCC) and see if I can spot any potential issues. Another set of eyes would really help. Will this transform work unconditionally?Two things are absolutely necessary,
Please let me know your thoughts. |
@prometheansacrifice what is the practical benefit we are getting here again, do we know how many bytes were saving this way? It's kinda convoluted so i'm not sure the added fragility to the build is worth it unless its a significant savings yeah? |
text: string, | ||
): void, | ||
}; | ||
// declare export type HostConfig<T, P, I, TI, HI, PI, C, CC, CX, PL> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are they commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those types, particularly ssr and mutation blocks need to be flattened.
"react": "^16.3.0", | ||
"react-reconciler": "0.10.0", | ||
"warning": "^3.0.0" | ||
"fbjs": "^0.8.17" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i really don't want a dep on fbjs if we can help it, its more of an internal FB project, and REact itself is moving away from including it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. It helped us avoid duplicate declarations for warning and other modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i wonder if it's worth making out own one for that? I have a package react-tackle-box i dump random common stuff into, if it's helpful i could put stuff there
@jquense Did you get a chance to look at the GCC'd bundle? |
I haven't had a chance to check yet :/ anything in particular you want me to see? Sorry it's been a while! |
Run the build with debug: true. You notice that all host config has completely disappeared from the bundle. Bundle size drops a few KBs. I understand the fragility you mentioned. Maybe we could put this behind a Without modifiying the AST, I exhausted all my options. Upstream works differently. Actually this transform tries to mimick the upstream AST after bundling. |
Attempts to close #27