Repository navigation
perf: stop paying for simctl and a deep snapshot before every simulator dump #523
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
Open
avilashp-sportsbet
wants to merge
2
commits into
mobile-next:main
Choose a base branch
from
avilashp-sportsbet:perf/cache-simulator-flutter-probe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package devices | ||
|
|
||
| import "testing" | ||
|
|
||
| // A verdict that outlives the process it was taken for is the only way this | ||
| // cache can be wrong, and it would be wrong silently: a Flutter app would be | ||
| // dumped through the accessibility tree, or a native app would be probed for a | ||
| // Dart VM on every dump. The tests below pin the rules that prevent that. | ||
| func TestFlutterCandidateIsRememberedForTheSameProcess(t *testing.T) { | ||
| t.Cleanup(func() { delete(simulatorFlutterCandidates, "udid-1") }) | ||
|
|
||
| if _, ok := cachedFlutterCandidate("udid-1", 100); ok { | ||
| t.Fatal("an unknown simulator must not have a verdict") | ||
| } | ||
|
|
||
| rememberFlutterCandidate("udid-1", 100, true) | ||
|
|
||
| isCandidate, ok := cachedFlutterCandidate("udid-1", 100) | ||
| if !ok || !isCandidate { | ||
| t.Errorf("the verdict for the same process must be reused, got (%v, %v)", isCandidate, ok) | ||
| } | ||
| } | ||
|
|
||
| // A reinstall can replace a native build with a Flutter one under the same | ||
| // bundle id, so the pid, not the bundle id, is what the verdict is tied to. | ||
| func TestFlutterCandidateIsLookedAtAgainAfterTheAppRestarts(t *testing.T) { | ||
| t.Cleanup(func() { delete(simulatorFlutterCandidates, "udid-2") }) | ||
|
|
||
| rememberFlutterCandidate("udid-2", 100, false) | ||
|
|
||
| if _, ok := cachedFlutterCandidate("udid-2", 101); ok { | ||
| t.Error("a relaunched or reinstalled app has a new pid and must be looked at again") | ||
| } | ||
| } | ||
|
|
||
| // The agent reports pid 0 when it cannot name the foreground process. Storing | ||
| // a verdict against it would pin an answer that no app relaunch could ever | ||
| // clear, so paying the simctl call again is the cheaper mistake. | ||
| func TestFlutterCandidateIsNotRememberedWithoutAProcessID(t *testing.T) { | ||
| t.Cleanup(func() { delete(simulatorFlutterCandidates, "udid-3") }) | ||
|
|
||
| rememberFlutterCandidate("udid-3", 0, true) | ||
|
|
||
| if _, ok := cachedFlutterCandidate("udid-3", 0); ok { | ||
| t.Error("a verdict that cannot be invalidated must not be stored") | ||
| } | ||
| if _, ok := cachedFlutterCandidate("udid-3", 100); ok { | ||
| t.Error("a verdict stored without a pid must not be served to a real process") | ||
| } | ||
| } | ||
|
|
||
| // Pids are per simulator, so two booted simulators running different apps can | ||
| // hand out the same number; the udid has to be part of the key. | ||
| func TestFlutterCandidatesAreNotSharedBetweenSimulators(t *testing.T) { | ||
| t.Cleanup(func() { | ||
| delete(simulatorFlutterCandidates, "udid-4") | ||
| delete(simulatorFlutterCandidates, "udid-5") | ||
| }) | ||
|
|
||
| rememberFlutterCandidate("udid-4", 100, true) | ||
|
|
||
| if _, ok := cachedFlutterCandidate("udid-5", 100); ok { | ||
| t.Error("two simulators can run the same pid; a verdict must not cross over") | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Cache the verdict only after the bundle check gives a trustworthy answer.
isFlutterAppBundlereturnsfalsewhenrunSimctl("get_app_container", ...)fails. It also returnsfalsewhen the path is empty.foregroundFlutterCandidatestores that result under the current PID withrememberFlutterCandidate.A transient
simctlfailure, such as one that occurs while the app is starting, then becomes a permanentfalseverdict for that process. A Flutter app stays on the accessibility fallback until it relaunches.Make
isFlutterAppBundlereturn a third state (an error). SkiprememberFlutterCandidatewhen the check fails. Treat the failed check as "not a candidate" for that call only.Proposed direction
checkFlutterAppBundlemust return an error forrunSimctlfailures and for an empty path. It must return(false, nil)only when the framework directory is confirmed absent.🤖 Prompt for AI Agents