Skip to content

Commit

Permalink
🛑Disable all perf observers in inabox. (#28125)
Browse files Browse the repository at this point in the history
* disable most observers inabox

* move disable to registerPerformanceObserver
  • Loading branch information
calebcordry committed Apr 30, 2020
1 parent 073fdae commit 68eaf0f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/service/performance-impl.js
Expand Up @@ -289,6 +289,14 @@ export class Performance {
* See https://github.com/WICG/paint-timing
*/
registerPerformanceObserver_() {
// Turn off performanceObserver derived metrics for inabox as there
// will never be a viewer to report to.
// TODO(ccordry): we are still doing some other unnecessary measurements for
// the inabox case, but would need a larger refactor.
if (getMode(this.win).runtime === 'inabox') {
return;
}

// Chromium doesn't implement the buffered flag for PerformanceObserver.
// That means we need to read existing entries and maintain state
// as to whether we have reported a value yet, since in the future it may
Expand Down
25 changes: 25 additions & 0 deletions test/unit/test-performance.js
Expand Up @@ -1351,4 +1351,29 @@ describes.realWin('PeformanceObserver metrics', {amp: true}, (env) => {
]);
});
});

describe('inabox environment', () => {
let PerformanceObserverConstructorStub;

beforeEach(() => {
PerformanceObserverConstructorStub = env.sandbox.stub(
env.win,
'PerformanceObserver'
);
});

it('disables many observers', () => {
PerformanceObserverConstructorStub.supportedEntryTypes = [
'navigation',
'largest-contentful-paint',
'first-input',
'layout-shift',
];
installPerformanceService(env.win);
env.win.__AMP_MODE.runtime = 'inabox';
Services.performanceFor(env.win);
// Each supported entryType currently leads to creation of new observer.
expect(PerformanceObserverConstructorStub).not.to.be.called;
});
});
});

0 comments on commit 68eaf0f

Please sign in to comment.