fix: disable background throttling also in the `viz::DisplayScheduler` by michal-pichlinski-openfin · Pull Request #38924 · electron/electron · GitHub
Skip to content

fix: disable background throttling also in the viz::DisplayScheduler - #38924

Merged
jkleinsc merged 10 commits into
electron:mainfrom
michal-pichlinski-openfin:fix-31016
Sep 26, 2023
Merged

jkleinsc merged 10 commits into
electron:mainfrom
michal-pichlinski-openfin:fix-31016

Conversation

@michal-pichlinski-openfin

@michal-pichlinski-openfin michal-pichlinski-openfin commented Jun 26, 2023 •

Copy link
Copy Markdown
Contributor

Description of Change

viz::DisplayScheduler is responsible for drawing and swapping frames in the DisplayScheduler::DrawAndSwap which is called from the DisplayScheduler::AttemptDrawAndSwap if the DisplayScheduler::ShouldDraw returns true. ShouldDraw depends on the DisplayScheduler visibility and when it is not visible then it returns false.

In order to keep producing frames, disabling backgroundThrottling should also prevent changing DisplayScheduler visibility to false.

DisplayScheduler lives in the ui::Compositor where every electron::NativewWindow has its own Compositor. electron::NativewWindow may be host of the multiple electron::api::WebContents instances which may have different WebPreferences settings. Therefore if at least one of the WebContents requires disabling throttling then all other WebContents using the same window will have it disabled in the ui::Compositor.

BREAKING CHANGE:
backgroundThrottling set to false will disable frames throttling in the BrowserWindow for all WebContents displayed by it.

Closes: #31016

Checklist

Release Notes

Notes: Fixed generating frames when the window is hidden and backgroundThrottling is disabled.

`viz::DisplayScheduler` is responsible for drawing and swapping frames
in the `DisplayScheduler::DrawAndSwap` which is called from the
`DisplayScheduler::AttemptDrawAndSwap` if the `DisplayScheduler::ShouldDraw`
returns true. `ShouldDraw` depends on the `DisplayScheduler` visibility
and when it is not visible then it returns false.

In order to keep producing frames, disabling `backgroundThrottling`
should also prevent changing `DisplayScheduler` visibility to false.

`DisplayScheduler` lives in the `ui::Compositor` where every
`electron::NativewWindow` has its own `Compositor`. `electron::NativewWindow`
may be host of the multiple `electron::api::WebContents` instances which may
have different `WebPreferences` settings. Therefore if at least one
of the `WebContents` requires disabling throttling then all other `WebContents`
using the same window will have it disabled in the `ui::Compositor`.

BREAKING CHANGE:
`backgroundThrottling` set to false will disable frames throttling
in the `BrowserWindow` for all `WebContents` displayed by it.

Close: [electron#31016](electron#31016)
@michal-pichlinski-openfin
michal-pichlinski-openfin requested a review from a team as a code owner June 26, 2023 17:13
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jun 26, 2023
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jul 3, 2023
@codebytere codebytere added the semver/patch backwards-compatible bug fixes label Jul 10, 2023

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change looks good to me.

/cc @electron/wg-upgrades to review the patch.

@codebytere codebytere left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this something that Chromium would accept upstream in any form? it'd be good to have a roadmap for this patch that isn't us floating it indefinitely.

Comment thread docs/api/structures/web-preferences.md Outdated
Comment thread docs/api/structures/web-preferences.md Outdated
Comment thread shell/browser/native_window.cc Outdated
@michal-pichlinski-openfin

Copy link
Copy Markdown
Contributor Author

@zcbenz
zcbenz requested a review from codebytere August 1, 2023 06:20
@michal-pichlinski-openfin

Copy link
Copy Markdown
Contributor Author

Is this something that Chromium would accept upstream in any form? it'd be good to have a roadmap for this patch that isn't us floating it indefinitely.

I think this may have lower chances to upstream than allow_disabling_blink_scheduler_throttling_per_renderview.patch which exists from the Dec 2019, because disabling throttling in Compositor affects all WebContents displayed by it.

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like the patch needs to be updated.
You can update the patch by running:

e sync --3

and then running

e patches all

@michal-pichlinski-openfin

Copy link
Copy Markdown
Contributor Author

Looks like the patch needs to be updated. You can update the patch by running:

e sync --3

and then running

e patches all

Patches updated, builds failed on Get depot tools step with error:

error: repository lacks the necessary blob to perform 3-way merge.
Falling back to direct application...
error: patch failed: gclient.py:712
error: gclient.py: patch does not apply

@codebytere

Copy link
Copy Markdown
Member

@michal-pichlinski-openfin this has been fixed in latest main - you need to rebase

@jkleinsc jkleinsc added semver/major incompatible API changes and removed semver/patch backwards-compatible bug fixes labels Sep 14, 2023

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@michal-pichlinski-openfin
michal-pichlinski-openfin requested a review from a team as a code owner September 15, 2023 05:25
@michal-pichlinski-openfin

Copy link
Copy Markdown
Contributor Author

Linux test runs failed due to: Forked prs not allowed to run on OSS projects.

@codebytere

Copy link
Copy Markdown
Member

@michal-pichlinski-openfin that's a flake that occasionally happens - could you please rebase on main?

@michal-pichlinski-openfin

Copy link
Copy Markdown
Contributor Author

This failure looks unrelated to my change:

        # Subtest: errors/force_colors.js
        not ok 18 - errors/force_colors.js
          ---
          duration_ms: 2169.073392
          failureType: 'testCodeFailure'
          error: |-
            Expected values to be strictly equal:
            + actual - expected ... Lines skipped
            
              '*force_colors.js:1\n' +
                "throw new Error('Should include grayed stack trace')\n" +
            ...
                '\x1B[90m    at Module.load (node:internal*modules*cjs*loader:1126:32)\x1B[39m\n' +
                '\x1B[90m    at Module._load (node:internal*modules*cjs*loader:967:12)\x1B[39m\n' +
            +   '\x1B[90m    at Module._load (node:electron*js2c*asar_bundle:763:32)\x1B[39m\n' +
            -   '\x1B[90m    at Module._load (node:electron*js2c*asar_bundle:777:32)\x1B[39m\n' +
                '\x1B[90m    at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:101:12)\x1B[39m\n' +
                '\x1B[90m    at node:internal*main*run_main_module:23:47\x1B[39m\n' +
                '\n' +
                'Node.js *\n'
          code: 'ERR_ASSERTION'
          name: 'AssertionError'
          expected: |-
            *force_colors.js:1
            throw new Error('Should include grayed stack trace')
            ^
            
            Error: Should include grayed stack trace
                at Object.<anonymous> (/test*force_colors.js:1:7)
                at Module._compile (node:internal*modules*cjs*loader:1271:14)
                at Module._extensions..js (node:internal*modules*cjs*loader:1326:10)
                at Module.load (node:internal*modules*cjs*loader:1126:32)
                at Module._load (node:internal*modules*cjs*loader:967:12)
                at Module._load (node:electron*js2c*asar_bundle:777:32)
                at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:101:12)
                at node:internal*main*run_main_module:23:47
            
            Node.js *
            
          actual: |-
            *force_colors.js:1
            throw new Error('Should include grayed stack trace')
            ^
            
            Error: Should include grayed stack trace
                at Object.<anonymous> (/test*force_colors.js:1:7)
                at Module._compile (node:internal*modules*cjs*loader:1271:14)
                at Module._extensions..js (node:internal*modules*cjs*loader:1326:10)
                at Module.load (node:internal*modules*cjs*loader:1126:32)
                at Module._load (node:internal*modules*cjs*loader:967:12)
                at Module._load (node:electron*js2c*asar_bundle:763:32)
                at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:101:12)
                at node:internal*main*run_main_module:23:47
            
            Node.js *
            
          operator: 'strictEqual'
          stack: |-
            assertSnapshot (/home/builduser/project/src/third_party/electron_node/test/common/assertSnapshot.js:38:12)
            async Module.spawnAndAssert (/home/builduser/project/src/third_party/electron_node/test/common/assertSnapshot.js:67:3)
            async TestContext.<anonymous> (file:///home/builduser/project/src/third_party/electron_node/test/parallel/test-node-output-errors.mjs:58:7)
            async Test.run (node:internal/test_runner/test:572:9)
            async Promise.all (index 17)
            async Suite.run (node:internal/test_runner/test:815:7)
            async startSubtest (node:internal/test_runner/harness:202:3)
          ...

@michal-pichlinski-openfin

Copy link
Copy Markdown
Contributor Author

@jkleinsc

The breaking change should be documented in https://github.com/electron/electron/blob/main/docs/breaking-changes.md

Addressed in: 4212433

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

API LGTM

@itsananderson

Copy link
Copy Markdown
Member

API LGTM

@welcome

welcome Bot commented Sep 26, 2023

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk

release-clerk Bot commented Sep 26, 2023 •

Copy link
Copy Markdown

Release Notes Persisted

Setting backgroundThrottling to false will disable frames throttling in the BrowserWindow for all WebContents displayed by it.

@fanchenio

Copy link
Copy Markdown

Can this be updated to electron26?

@dsanders11

Copy link
Copy Markdown
Member

MrHuangJser pushed a commit to MrHuangJser/electron that referenced this pull request Dec 11, 2023
electron#38924)

* fix: disable background throttling also in the `viz::DisplayScheduler`

`viz::DisplayScheduler` is responsible for drawing and swapping frames
in the `DisplayScheduler::DrawAndSwap` which is called from the
`DisplayScheduler::AttemptDrawAndSwap` if the `DisplayScheduler::ShouldDraw`
returns true. `ShouldDraw` depends on the `DisplayScheduler` visibility
and when it is not visible then it returns false.

In order to keep producing frames, disabling `backgroundThrottling`
should also prevent changing `DisplayScheduler` visibility to false.

`DisplayScheduler` lives in the `ui::Compositor` where every
`electron::NativewWindow` has its own `Compositor`. `electron::NativewWindow`
may be host of the multiple `electron::api::WebContents` instances which may
have different `WebPreferences` settings. Therefore if at least one
of the `WebContents` requires disabling throttling then all other `WebContents`
using the same window will have it disabled in the `ui::Compositor`.

BREAKING CHANGE:
`backgroundThrottling` set to false will disable frames throttling
in the `BrowserWindow` for all `WebContents` displayed by it.

Close: [electron#31016](electron#31016)

* fixup! fix: disable background throttling also in the `viz::DisplayScheduler`

* fixup! fix: disable background throttling also in the `viz::DisplayScheduler`

* fixup! fix: disable background throttling also in the `viz::DisplayScheduler`

---------

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Disabling backgroundThrottling not working with hide() on Windows

7 participants