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

Investigate options for reducing package size with code elimination #7867

Closed
bretg opened this issue Dec 16, 2021 · 2 comments
Closed

Investigate options for reducing package size with code elimination #7867

bretg opened this issue Dec 16, 2021 · 2 comments
Assignees
Labels

Comments

@bretg
Copy link
Collaborator

bretg commented Dec 16, 2021

Type of issue

optimization

Description

There have been conversations about trying to make the overall PBJS built package smaller by allowing bid adapters to tag code as having a certain optional function. Publishers could then build a package that excludes certain code. For instance, if the publisher doesn't need Native support in their wrapper, it may be possible to save several KB by not including code related to support of the Native mediatype.

There were several ideas kicked around in PR #6079

Moving that conversation here.

The original proposal from @pm-harshad-mane was a pre-processor model. e.g.:

// removeIf(disableNativeRelatedCode)
import { processNativeAdUnitParams, nativeAdapters } from './native.js';
// endRemoveIf(disableNativeRelatedCode)

A counter-proposal (from @dgirardi):

The reason this approach does reduce bundle size is that it removes live code that happens to never get run. I agree that it seems hard to maintain. To me the main issue seems to be that a lot of code looks for particular settings or request/response values that keep code alive, even if you (as the publisher) know they will never be there. I think a better approach would be to programmatically put "breakpoints" around access to those values.
For example, instead of:

     switch (bid.mediaType) {
           case NATIVE: doNativeStuff();
     }

we could have something like:

  bid.ifNative(doNativeStuff);

and define ifNative based on build settings. This would still be a major refactor, but it has the advantage that it would automatically "cascade" dead code detection to all dependencies, you wouldn't have to (for example) care about imports that only get used inside doNativeStuff like you do here.

@ChrisHuie
Copy link
Collaborator

A webpack proposal for this is referenced in #6179

@patmmccann
Copy link
Collaborator

merged

Repository owner moved this from In progress to Done in Prebid.js Tactical Issues table Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

4 participants