Skip to content
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

[web] remove obsolete object caches; simplify native object management #40862

Merged
merged 1 commit into from Apr 3, 2023

Conversation

yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Apr 2, 2023

(this is attempt 2; details below)

Remove obsolete object caches and introduce a simpler way to manage native objects:

  • Remove the unused SynchronousSkiaObjectCache.
  • Introduce new library native_memory.dart that's smaller and simpler than skia_object_cache.dart.
  • Introduce two types of native object references:
    • UniqueRef a reference with a unique Dart object owner.
    • CountedRef a ref-counted reference with multiple Dart object owners.
  • All native references use GC (via FinalizationRegistry) as a back-up.
  • The new library removes everything related to object resurrection that was needed only in browsers that didn't support FinalizationRegistry. All browsers support it now.
  • Remove the ad hoc SkParagraph cache that predates the introduction of Paragraph.dispose.
  • Rewrite CkParagraph in terms of UniqueRef.
  • Rewrite CkImage in terms of CountedRef; delete SkiaObjectBox.

This PR does not migrate all objects from the old skia_object_cache.dart to native_memory.dart. That would be too big of a change. The migration can be done in multiple smaller PRs.

This also removes a few unnecessary relayouts observed in flutter/flutter#120921, but not all of them (more details in flutter/flutter#120921 (comment))

About attempt 2

This is the second attempt to land this. The first attempt (#40617) was reverted (#40861).

The issue with the first attempt was in the expression SkObjectFinalizationRegistry((UniqueRef<Object> uniq) {...}.toJS), which as of right now is not supported by dart2js. This second iteration uses js_util.callConstructor to invoke the constructor. I'm not sure why it didn't trigger in our tests, but I suspect the difference is in how dart2js handles code between pre-rewritten SDK and post-rewritten SDK.

@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label Apr 2, 2023
@yjbanov yjbanov added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 3, 2023
@auto-submit auto-submit bot merged commit 07afddf into flutter:main Apr 3, 2023
40 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 3, 2023
CaseyHillers added a commit that referenced this pull request Apr 3, 2023
yjbanov pushed a commit that referenced this pull request Apr 3, 2023
…anagement" (#40882)

Reverts #40862

Google Testing is failing on

```
The compiler crashed: root::dart:_engine::SkObjectFinalizationRegistry::@methods::|staticInteropFactoryStub is already bound to Reference to dart:_engine::SkObjectFinalizationRegistry::@methods::|staticInteropFactoryStub, trying to bind to Reference to SkObjectFinalizationRegistry.|staticInteropFactoryStub with node SkObjectFinalizationRegistry.|staticInteropFactoryStub (Procedure:1207727)
```
yjbanov added a commit that referenced this pull request Apr 4, 2023
#40894)

(this is attempt 3; details below)

Remove obsolete object caches and introduce a simpler way to manage
native objects:

* Remove the unused `SynchronousSkiaObjectCache`.
* Introduce new library `native_memory.dart` that's smaller and simpler
than `skia_object_cache.dart`.
* Introduce two types of native object references:
  * `UniqueRef` a reference with a unique Dart object owner.
* `CountedRef` a ref-counted reference with multiple Dart object owners.
* All native references use GC (via `FinalizationRegistry`) as a
back-up.
* The new library removes everything related to object resurrection that
was needed only in browsers that didn't support `FinalizationRegistry`.
All browsers support it now.
* Remove the ad hoc `SkParagraph` cache that predates the introduction
of `Paragraph.dispose`.
* Rewrite `CkParagraph` in terms of `UniqueRef`.
* Rewrite `CkImage` in terms of `CountedRef`; delete `SkiaObjectBox`.

This PR does not migrate all objects from the old
`skia_object_cache.dart` to `native_memory.dart`. That would be too big
of a change. The migration can be done in multiple smaller PRs.

This also removes a few unnecessary relayouts observed in
flutter/flutter#120921, but not all of them
(more details in
flutter/flutter#120921 (comment))

## About attempt 3

More about [attempt 2
here](#40862).

In this attempt 3 I'm replacing the `factory` with a top-level function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
2 participants