-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Bundle size inflated due to intra-module dependencies #7936
Comments
having duplicate code show up in a the as for even though modules can't directly import other modules using es6 imports it is possible for modules to have dependencies on other modules but it is handled through the module/submodule pattern (which came up years after the prebid module system was implemented so i don't necessarily think it's the greatest solution and kinda hacky). you can see an example of this with the userId module: Prebid.js/modules/userId/index.js Line 862 in d8282ec
Prebid.js/modules/imuIdSystem.js Line 151 in d8282ec
there are several userId submodules that depend on the userId module as well as other module/submodule relationships defined here. while this does allow modules to depend on each other i'm not a huge fan because: it's a custom-coded dependency that's hidden to tooling such as IDEs, it's resolved at runtime which is not ideal, and it relies on conventions such as updating that .submodules.json file which the gulp build system uses which could introduce discrepancies keeping the file up-to-date with reality. if the module/submodule issues are something you wanted to address during this refactor of webpack modules i think it could be beneficial, although i also understand how it might be out-of-scope. |
@snapwich that makes sense (and I did not know that multiple analytics adapters are unlikely), but I also think it's unavoidable that over time this model will cause dead code to accumulate (because it relies ultimately on putting significant effort into code reviews). For example, this utility function: Lines 912 to 920 in 55e7cdb
Is used only in 3 modules ( From a technical POV, it shouldn't be hard to fix this, but I am not familiar with how the build output is used by 3rd party tools. I am thinking we can keep it as-is for compatibility but also generate a separate build that lets webpack track dependencies between chunks and capturing that into something that 3rd party tools can use. It should be possible for example to have something like
|
so it's true that there will be "dead code" for some users depending the combination of modules and/or features you choose to use. as you identified, some modules added or use shared util functions that really are only used in a one or few modules. this can be essentially solved by a publisher making their own prebid.js build from npm src, which many do. webpack performs tree-shaking to do dead code removal and if you are directly importing your modules using es6 syntax (as you should if you're using prebid from npm) webpack should be able to determine code you're not using and remove it. i haven't tested how friendly prebid is for tree-shaking, but i assume this is a solved problem; and if it's not then the bug fix should be making prebid friendly to webpack tree-shaking. this doesn't work for users that need to build prebid.js through concatenation though. it doesn't need to be concatenation but the requirement for these users is that they can make a custom prebid.js builds quickly (i.e. not run a webpack build which is extremely slow). an example would be a user requesting the bundle the last way in which prebid is customized is through features. it's pretty obvious now that if you use prebid.js but are not doing video, you are including a lot of video code in the prebid-core.js that you are not going to use. so it's essentially "dead code". solutions to this have been discussed in a few different threads. here's one i see that is still open: #6361 these are the three use cases i think you should be considering when refactoring the build process. |
fwiw, using multiple analytics adapters is not uncommon |
@snapwich this was intentional and highlighted at the time in #6308 (comment) as there is no 'command bus' to let modules communicate with one another...or at least there was not at the time. The aim is to reduce the burden on AdOps teams so they do not have to duplicate identical configuration snippets across the three Adloox modules. |
Type of issue
Bug
Description
Prebid bundles are generated by concatenating "prebid-core.js" with a user-selected list of module files, which contain all dependencies of the module that are not in core.
Since there is no real dependency tracking beside "core" or "not core", dependencies can be repeated across module files (if they import from each other, or if they import the same non-core file).
Fixing this requires coordination with external bundle vendors.
Steps to reproduce
Generated
prebid.js
: https://gist.github.com/dgirardi/86947f196a25fc753fbb6403094b97feAnalyticsAdapter
definition is repeated at lines #14737, #15830, #16447adlooxAnalyticsAdapter
module is repeated at lines #14377, #15470Problem persists in minified bundle, just harder to spot:
Generated
prebid.js
: https://gist.github.com/dgirardi/c3bb01de917407746950ec597cefbab2"bundle"
(from here) appears 3 timeswindow.pbjs.installedModules.push("adlooxAnalyticsAdapter")
appears twiceThe text was updated successfully, but these errors were encountered: