-
Notifications
You must be signed in to change notification settings - Fork 6k
Plumbing refactor to allow the usage of Dart_CreateIsolateInGroup #23549
Conversation
d255c92 to
5a280fe
Compare
5a280fe to
3d179a5
Compare
3d179a5 to
816caac
Compare
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
chinmaygarde
left a comment
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.
This breaks the existing behavior that terminating the root isolate also terminates any isolates spawned by it. It should be possible to create distinct isolate groups with shared resources. Also, what resources are being duplicated during isolate creation?
runtime/dart_isolate.h
Outdated
| /// possible with the caller DartIsolate. This allows them to | ||
| /// occupy less memory together. | ||
| /// @attention Only certain setups can take advantage of the most savings | ||
| /// currently, release builds currently. |
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.
@mkustermann where do you estimate you guys will land by the next Flutter stable?
xster
left a comment
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.
LGTM. Please wait for @chinmaygarde to review.
runtime/dart_isolate.h
Outdated
| //---------------------------------------------------------------------------- | ||
| /// @brief Creates a running DartIsolate who shares as many resources as | ||
| /// possible with the caller DartIsolate. This allows them to | ||
| /// occupy less memory together. |
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.
Describe their and their components' lifecycles. Describe restrictions (i.e. they must be from the same aot).
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.
Done
shell/common/engine.h
Outdated
| //---------------------------------------------------------------------------- | ||
| /// @brief Create a Engine that shares as many resources as | ||
| /// possible with the calling Engine such that together | ||
| /// they occupy less memory. |
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.
Same comment for doc. Can use more details.
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.
Done, mostly linked to other documentation.
| public: | ||
| template <class T> | ||
| using CreateCallback = std::function<std::unique_ptr<T>(Shell&)>; | ||
| typedef std::function<std::unique_ptr<Engine>( |
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.
Kinda does the same thing as the above. Can we make the names sound similar like EngineCreateCallback or something?
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.
done
shell/common/shell.h
Outdated
| const CreateCallback<PlatformView>& on_create_platform_view, | ||
| const CreateCallback<Rasterizer>& on_create_rasterizer, | ||
| DartVMRef vm, | ||
| const EngineMaker& engine_maker); |
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.
Same here. Could this be something like on_create_engine for consistency?
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.
good idea, done
The isolate group, so the heap and GC and the loaded executable. This PR isn't making any functional changes. The top level APIs behaves the same. A spawned flutter engine and its isolate should live beyond its spawning engine, this matches the semantics of isolate groups and matches how engine groups will work. I've added a comment to where the functional change will be made, conditionally we will be calling Dart_CreateIsolateInGroup instead of Dart_CreateIsolateGroup. I avoided turning it fully on yet until I can finish all the phase 1 work. I brought this over because this refactor makes other phase 1 work possible. You can see it in action in the prototype https://github.com/gaaclarke/engine/tree/spawn-engine edit:
No existing APIs have have had their semantics changed by this PR or any of the others. This is a whole different API so it's not a breaking change. |
That is not what I meant. Existing Flutter apps expect that isolates spawned by their root isolate will be terminated with the root isolate is collected. This will not be the case for isolates spawned using this new call. This deviation from expected behavior is the breaking change I meant.
The heap should be per isolate and not the group. The GC and other VM components are owned by the Dart VM instance and not the isolate group. The loaded executable code should be handled by libdl and reference counted already. So, in bytes, what are the resources you are saving by using this vs the old APIs. |
|
@chinmaygarde This is a whole new API so there isn't any expectations. The behavior you are describing is definitive to the work we are doing. The heap isn't per isolate, it is per group although there are safeguards that disallow them from directly accessing memory allocated to a different isolate (there is plans to change that). With respect to the loaded program it isn't a problem with occupied memory but the time to create a new isolate. Loading the executable takes a sizable chunk of the time to create a new isolate, in this case it is just wasted effort. All this work is outlined in this issue: dart-lang/sdk#36097 I think there is a design doc floating around, too. |
82dfe3d to
1e15db8
Compare
| std::unique_ptr<IsolateConfiguration> isolate_configration, | ||
| std::shared_ptr<VolatilePathTracker> volatile_path_tracker); | ||
| std::shared_ptr<VolatilePathTracker> volatile_path_tracker, | ||
| const DartIsolate* spawning_isolate = nullptr); |
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.
if you change the signature, update the method doc
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.
Done
runtime/dart_isolate.h
Outdated
| /// @brief Creates a running DartIsolate who shares as many resources as | ||
| /// possible with the caller DartIsolate. This allows them to | ||
| /// occupy less memory together and to be created faster. | ||
| /// @details Shared components will be destroyed when the last DartIsolate |
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.
when the last DartIsolate among the group. Might be misunderstood as if you make 1, 2, 3, 4, shared components will be destroyed if 4 is destroyed.
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.
updated
| const DartIsolate* spawning_isolate = nullptr); | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Creates a running DartIsolate who shares as many resources as |
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.
Creates a new running DartIsolate from the current DartIsolate
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.
I don't think that is much of an improvement. Hopefully the other edits cover the information you are trying to convey with that.
runtime/dart_isolate.h
Outdated
| /// @details Shared components will be destroyed when the last DartIsolate | ||
| /// is destroyed. SpawnIsolate can only be used to create | ||
| /// DartIsolates whose executable code is shared with the calling | ||
| /// DartIsolate. |
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.
Does the current DartIsolate need to be in any particular states before calling this?
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.
I'm not sure of the hard requirements of Dart_CreateIsolateInGroup. It isn't spelled out in its documentation.
runtime/dart_isolate.h
Outdated
| /// DartIsolate. | ||
| /// @attention Only certain setups can take advantage of the most savings | ||
| /// currently, AOT specifically. | ||
| /// @return A running DartIsolate. |
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.
A new, running DartIsolate.
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.
done
| /// DartIsolates whose executable code is shared with the calling | ||
| /// DartIsolate. | ||
| /// @attention Only certain setups can take advantage of the most savings | ||
| /// currently, AOT specifically. |
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.
Add the same disclosure for why it's a weak pointer, who owns it, performance considerations etc.
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.
done
shell/common/engine.h
Outdated
| /// possible with the calling Engine such that together | ||
| /// they occupy less memory and be created faster. | ||
| /// @details This method ultimately calls DartIsolate::SpawnIsolate to make | ||
| /// sure resources are shared. |
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.
Same doc comments. Does the current engine need to be in any state before calling this? Mention that it's a new Engine.
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.
Done.
| /// @details This version of Create can take in a running DartVMRef and a | ||
| /// function that defines how the Shell's Engine should be | ||
| /// created. | ||
| /// @param[in] vm A running DartVMRef where this Shell's Dart |
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.
Do you want to briefly describe how one typically gets a DartVMRef?
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.
I don't know if we should point to DartVMRef::Create, it's pretty straightforward
chinmaygarde
left a comment
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.
Mostly looks good. Please add tests for Engine::Spawn to shell_unittests and for DartIsolate::SpawnIsolate to runtime_unittests.
A dependent PR has a unit test for Engine::Spawn #23603 SpawnIsolate has test coverage via the golden image test for spawning engines and the FlutterEngineTests of objective-c. I'll look into seeing if I can get a unit test directly on SpawnIsolate. |
You should be able to base the test on SGTM about the test in the dependent PR. |
* 51dd6aa [web] Enable the new rich paragraph implementation (flutter/engine#23162) * 0f9fc3d Roll Skia from 7cf3addb1bd8 to 93c2d81f199a (1 revision) (flutter/engine#23614) * a1e7424 [dart-runner] Avoid calling Destroy on nullptr (flutter/engine#23608) * 846d958 Windows textures: Add placeholder flutter_texture_registrar.h (flutter/engine#23623) * 55afc18 Roll Dart SDK from 7fcbd388b620 to ef8bf7f0a667 (5 revisions) (flutter/engine#23628) * d2b8154 [canvaskit] apply invser scale on the left (flutter/engine#23550) * be1a3c0 Roll Fuchsia Linux SDK from UB6RsTbdU... to FfWbbB4r8... (flutter/engine#23633) * f743c89 Roll Skia from 93c2d81f199a to 9fd75e96d712 (29 revisions) (flutter/engine#23635) * cf42dbe Roll wuffs to google/wuffs@c86add2 (flutter/engine#23607) * f1278d0 Link SkShaper/SkParagraph into the engine by default (flutter/engine#23626) * fb56b4b Android deeplink sends "path + query" instead of just path (flutter/engine#23561) * 22bb891 Plumbing refactor to allow the usage of Dart_CreateIsolateInGroup (flutter/engine#23549) * 20991a5 Add accessibility suport to Linux shell. (flutter/engine#19634) * 145922b Roll Dart SDK from ef8bf7f0a667 to 636ff0ec97e0 (1 revision) (flutter/engine#23639) * 176ae6e Roll Fuchsia Mac SDK from oll0Dgp9o... to JSzm8D59u... (flutter/engine#23641) * d2320a8 Roll Dart SDK from 636ff0ec97e0 to d3d7b77e8165 (1 revision) (flutter/engine#23642) * 8bdd099 Roll Skia from 9fd75e96d712 to 38ca513408d1 (1 revision) (flutter/engine#23643) * cc572e1 Roll Skia from 38ca513408d1 to be2a8614c5d6 (2 revisions) (flutter/engine#23644) * e9383a0 Roll Dart SDK from d3d7b77e8165 to 010633edc631 (1 revision) (flutter/engine#23645) * 9d6ed8b Roll Fuchsia Linux SDK from FfWbbB4r8... to BUsKF6z4t... (flutter/engine#23646) * 6d55dd4 Roll Dart SDK from 010633edc631 to 724d9e5e7d71 (1 revision) (flutter/engine#23647) * 299f081 Roll Skia from be2a8614c5d6 to 0d7de6bc9ac3 (1 revision) (flutter/engine#23648) * 0ec99cf Roll Fuchsia Mac SDK from JSzm8D59u... to BsUY1yjWh... (flutter/engine#23650) * 859494f Revert "[web] Enable the new rich paragraph implementation (#23162)" (flutter/engine#23651) * 648dae9 Roll Skia from 0d7de6bc9ac3 to 92969f265686 (7 revisions) (flutter/engine#23652)
…utter#23549) Did the plumbing refactor that allows us to call Dart_CreateIsolateInGroup when applicable.
…utter#23549) Did the plumbing refactor that allows us to call Dart_CreateIsolateInGroup when applicable.
Description
This should be a noop refactor that plumbs spawning all the way down to the dart isolate so that it can use Dart_CreateIsolateInGroup if necessary.
Related Issues
flutter/flutter#72025
Tests
I added the following tests:
This is just a refactor, no new or changed functionality, existing tests should cover it.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.Reviewer Checklist
Breaking Change
Did any tests fail when you ran them? Please read handling breaking changes.