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

Prebid core & PBS adapter: Feature tags and optional compilation of native support #8219

Merged
merged 27 commits into from
Jun 17, 2022

Conversation

dgirardi
Copy link
Collaborator

@dgirardi dgirardi commented Mar 25, 2022

Type of change

  • Feature
  • Does this change affect user-facing APIs or examples documented on http://prebid.org?

Description of change

This adds feature flags that can remove portions of the codebase at build time (see #7867).

The first (and only) flag defined here is "NATIVE", which is the easiest (and smallest) to manage; only core and PBS are included - with the expectation that adapters will over time mark their feature-specific code as is done here.

This is the effect on the bundle size:

demetrio@pbws:~/src/Prebid.js$ gulp build-bundle-prod --modules=prebidServerBidAdapter > /dev/null 2>&1 && ls -l build/dist/prebid.js
-rw-rw-r-- 1 demetrio demetrio 176791 Jan 27 11:21 build/dist/prebid.js
demetrio@pbws:~/src/Prebid.js$ gulp build-bundle-prod --modules=prebidServerBidAdapter --disable=native > /dev/null 2>&1 && ls -l build/dist/prebid.js
-rw-rw-r-- 1 demetrio demetrio 168356 Jan 27 11:21 build/dist/prebid.js

A readable comparison of the output: https://gist.github.com/dgirardi/c506a2aa243125cc2a8bdcfa27e10d7a/revisions

Other information

Testing: the strategy is, for now, to add an additional test run with all features disabled. Once we have more flags defined I intend to revisit this - it will probably be too expensive to run the whole test suite on all feature combinations, but I am optimistic that we can find a good heuristic to identify "relevant" tests and be exhaustive only on those (most tests do not interact with the code being removed).

Compilation: I have decided to use our Babel plugin to resolve feature flags (as opposed to webpack's DefinePlugin or other options like terser arguments). The reason is that it works better for npm consumers: no change is required to keep the build working, and there's no risk of our globals (i.e. FEATURES) clashing with their namespace.

Documentation PR: TBD

@patmmccann
Copy link
Collaborator

@pm-harshad-mane something to consider for the pubmatic adapter?

@ChrisHuie ChrisHuie self-requested a review April 6, 2022 16:46
@ChrisHuie ChrisHuie self-assigned this Apr 6, 2022
@snapwich snapwich self-assigned this Apr 27, 2022
Copy link
Collaborator

@snapwich snapwich left a comment

Choose a reason for hiding this comment

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

this is awesome. the PR is a bit out-of-date now and as you stated i think there's still some things to figure out regarding testing but overall i really like this approach of using dead-code elimination as well as using the babel plugin.

really nice

Copy link
Contributor

@mmoschovas mmoschovas left a comment

Choose a reason for hiding this comment

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

This looks good. One thing I am noticing while going through this (not to do with this PR but wanted to make mention of it) is that the Object.assign within PBS bid adapter is getting excessively long i.e. 500+ lines of code. We should really think about breaking this up a bit into some smaller functions to reduce complexity and make this more readable.

@patmmccann patmmccann merged commit 5b4987d into prebid:master Jun 17, 2022
@dgirardi
Copy link
Collaborator Author

@mmoschovas regarding the complexity, your input is welcome in #8562 - but overall I agree :)

@patmmccann
Copy link
Collaborator

@dgirardi this is released! Very exciting. Lmk when docs avail for review

@bretg
Copy link
Collaborator

bretg commented Jun 22, 2022

Anyone up for documenting this (awesome) feature so new bid adapters utilize it? Belongs in https://docs.prebid.org/dev-docs/bidder-adaptor.html#supporting-native

@dgirardi
Copy link
Collaborator Author

@bretg I'll write some docs.

renebaudisch pushed a commit to renebaudisch/Prebid.js that referenced this pull request Jun 28, 2022
…ative support (prebid#8219)

* Upgrade webpack to 5; gulp build works

* Fix karma, except events

* Uniform access to events, import * or require (import * from 'events.js' / import events from 'events.js' return different objects, which is a problem for stubbing)

* Fix (?) adapters that use `this` inappropriately

* Update webpack-bundle-analyzer

* Fix warnings

* Enable tree shaking

* Set webpack mode 'none' (or else tests fail (!))

* Update coreJS version in babelrc - prebid#7943

* Use babel to translate to commonjs only for unit tests; enable production mode

* Define feature flags at compile time - starting with just "NATIVE"

* Add build-bundle-verbose

* Run tests with all features disabled

* Fix build-bundle-verbose

* Tag native#nativeAdapters

* Merge master

* Add fsevents as optional dep

* Adjust syntax for node 12
@shahinrahbariasl
Copy link
Contributor

Hey @dgirardi , these are awesome changes!

One thing I noticed recently is that --watch flag for gulp test no longer works, probably because of it being hardcoded here, so gulp test always exits regardless of the flag. If I change watch: false to true in the above line, I can then use the --watch flag again and debug tests in chrome.

@dgirardi
Copy link
Collaborator Author

dgirardi commented Jul 6, 2022

@shahinrahbariasl how are you running gulp for development? I personally found all options too infuriating to use when I first dove in, so I'm not sure what people use in the wild. I work with gulp serve-and-test --file <spec_file> (watch mode is always on for it).

@shahinrahbariasl
Copy link
Contributor

shahinrahbariasl commented Jul 6, 2022

I usually do gulp test --file <path-to-test-file> --watch. The I can go to http://localhost:9876/ and use debugger in tests. I can try the above too.

bwhisp pushed a commit to bwhisp/Prebid.js that referenced this pull request Jul 13, 2022
…ative support (prebid#8219)

* Upgrade webpack to 5; gulp build works

* Fix karma, except events

* Uniform access to events, import * or require (import * from 'events.js' / import events from 'events.js' return different objects, which is a problem for stubbing)

* Fix (?) adapters that use `this` inappropriately

* Update webpack-bundle-analyzer

* Fix warnings

* Enable tree shaking

* Set webpack mode 'none' (or else tests fail (!))

* Update coreJS version in babelrc - prebid#7943

* Use babel to translate to commonjs only for unit tests; enable production mode

* Define feature flags at compile time - starting with just "NATIVE"

* Add build-bundle-verbose

* Run tests with all features disabled

* Fix build-bundle-verbose

* Tag native#nativeAdapters

* Merge master

* Add fsevents as optional dep

* Adjust syntax for node 12
@muuki88
Copy link
Collaborator

muuki88 commented Aug 1, 2022

We use an webpack build with prebid as a NPM dependency. This change breaks our js bundle at runtime with

secureCreatives.js:25 Uncaught ReferenceError: FEATURES is not defined
    at ./node_modules/prebid.js/src/secureCreatives.js (secureCreatives.js:25:1)
    at __webpack_require__ (bootstrap:19:1)
    at ./node_modules/prebid.js/src/prebid.js (polyfill.js:18:2)
    at __webpack_require__ (bootstrap:19:1)
    at make namespace object:7:1
    at moli.mjs:41251:3
    at moli.mjs:41253:12

As the FEATURE variable comes out of thin air :P

@wissamabyad
Copy link

We're running into the same issue, and can't upgrade beyond version 7.1, and the error is still not handled in 7.25.

secureCreatives.js?4527:24 Uncaught (in promise) ReferenceError: FEATURES is not defined
    at eval (secureCreatives.js?4527:24:1)
    at ../../node_modules/prebid.js/src/secureCreatives.js (prebid.js:413:1)
    at __webpack_require__ (main.js:1349:42)
    at eval (prebid.js:12:78)
    at ../../node_modules/prebid.js/src/prebid.js (prebid.js:389:1)
    at __webpack_require__ (main.js:1349:42)
    at eval (library.ts:5:67)
    at ../../lib/advertising/Prebid/library.ts (prebid.js:23:1)
    at Function.__webpack_require__ (main.js:1349:42)

@dgirardi
Copy link
Collaborator Author

@wissamabyad, are you passing prebid sources through our babel configuration as in the README?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.