prebid / Prebid.js

Setup and manage header bidding advertising partners without writing code or confusing line items. Prebid.js is open source and free.
https://docs.prebid.org
Apache License 2.0
1.33k stars 2.09k forks source link

Split long task #5054

Closed nanek closed 4 years ago

nanek commented 4 years ago

Type of issue

Question

Description

I've been researching ways to decrease the First Input Delay of our website. It is recommended to eliminate long tasks. Prebid profiles as a long task, particularly with a lot of bidders.

Good article on the topic, https://philipwalton.com/articles/idle-until-urgent/

Profile of prebid demonstrating long task. current

I've tested wrapping the ajaxBuilder call in a setTimeout resulting in the ajax calls getting split into different tasks as shown in the screenshot below. I picked this location as it seemed to be where a lot of time was spent and the ajax calls are already async so it should be safe. split

Are there any concerns with this approach? Are there other places where it would be more appropriate to split the work up to avoid a long task?

Not directly related, has there been any discussion lately on using web workers to move work off of the main thread?

Thanks!

pm-harshad-mane commented 4 years ago

Hello @nanek We really appreciate your findings. This looks good to me, can you create a PR for the same so others can also recommend changes if needed and we can pull this change into the master?

snapwich commented 4 years ago

I like the idea in general. I don't think wrapping the ajax call in a setTimeout is a good place to split for two reasons. 1) I'm not sure that this would actually improve performance. The work done in the ajax builder is very minimal (just building an XMLHttpRequest object) and these ajax requests are already asynchronous and non-blocking which means they are technically split work as the responses are handled on a separate call stack when they come in. 2) We don't want to delay our auction requests. For header bidding to work it's very important that the actual header bidding requests are sent ASAP to allow the auction sufficient time to perform before the page finishes rendering.

That said, there is probably places where we can split work with minimal effect on the auction and I'd be open to doing that.

Is it possible to set up a test page that I could look at your results? The flame graphs are interesting, but since it doesn't include a timeline and I can't dig into the stack it's hard for me to tell if the difference is as pronounced as the images show, or if the differences are ideal (i.e. if the auction was delayed).

Let me know, thanks!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.