Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Replace 'std::mutex' inside 'SyncSwitch' to 'fml::SharedMutex' #32773

Merged

Conversation

ColdPaleLight
Copy link
Member

@ColdPaleLight ColdPaleLight commented Apr 19, 2022

fix flutter/flutter#102144

SyncSwitch will be used for both frame rasterization on the Raster thread and texture upload on the IO thread.

But SyncSwitch uses std::mutex internally, which means only one thread can access it at a time. This poses a potential risk to the performance of Raster thread.

This PR proposes to change the std::mutex to a fml::SharedMutex.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM if LGT @gaaclarke

@gaaclarke
Copy link
Member

This is only a win if (time spent waiting on other thread's access to mutex > overhead of SharedMutex).

Given that the IO thread can occupy the mutex for a significant time I think this suggestion is reasonable. It would be nice if we had some sort of data to back up this decision.

Also, when the SyncSwitch was introduced there wasn't so many regions using it, so knowing what we know now it makes more sense. LGTM.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider replacing the mutex in SyncSwitch with a read-write lock
4 participants