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

Disable macro-after-long-task in inabox. #26459

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/chunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const TAG = 'CHUNK';
* @type {boolean}
*/
let deactivated = /nochunking=1/.test(self.location.hash);
let allowLongTasks = false;

/**
* @const {!Promise}
Expand Down Expand Up @@ -114,6 +115,14 @@ export function deactivateChunking() {
deactivated = true;
}

/**
* Allow continuing macro tasks after a long task (>5ms).
* In particular this is the case when AMP runs in the `amp-inabox` ads mode.
*/
export function allowLongTasksInChunking() {
allowLongTasks = true;
}

/**
* @visibleForTesting
*/
Expand Down Expand Up @@ -443,7 +452,11 @@ class Chunks {
// If we've spent over 5 millseconds executing the
// last instruction yeild back to the main thread.
// 5 milliseconds is a magic number.
if (this.bodyIsVisible_ && this.durationOfLastExecution_ > 5) {
if (
!allowLongTasks &&
this.bodyIsVisible_ &&
this.durationOfLastExecution_ > 5
) {
this.durationOfLastExecution_ = 0;
this.requestMacroTask_();
return;
Expand Down
3 changes: 2 additions & 1 deletion src/inabox/amp-inabox.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import '../polyfills';
import {Navigation} from '../service/navigation';
import {Services} from '../services';
import {adopt} from '../runtime';
import {allowLongTasksInChunking, startupChunk} from '../chunk';
import {cssText as ampSharedCss} from '../../build/ampshared.css';
import {doNotTrackImpression} from '../impression';
import {fontStylesheetTimeout} from '../font-stylesheet-timeout';
Expand All @@ -43,7 +44,6 @@ import {
} from '../style-installer';
import {internalRuntimeVersion} from '../internal-version';
import {maybeValidate} from '../validator-integration';
import {startupChunk} from '../chunk';
import {stubElementsForDoc} from '../service/custom-element-registry';

getMode(self).runtime = 'inabox';
Expand All @@ -69,6 +69,7 @@ try {
makeBodyVisibleRecovery(self.document);
throw e;
}
allowLongTasksInChunking();
startupChunk(self.document, function initial() {
/** @const {!../service/ampdoc-impl.AmpDoc} */
const ampdoc = ampdocService.getAmpDoc(self.document);
Expand Down