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

Conversation

@mdebbar
Copy link
Contributor

@mdebbar mdebbar commented Mar 11, 2020

Initially, this will be used in benchmarks to enable/disable canvas-based text layout.

Eventually, this can be used by app developers to control what experiments they want to use in their apps. Currently, the only way to control experiments would be through environment variables which are verbose and only work in release mode.

cc @hterkelsen I added the canvas kit flag in here too. Please let me know if you want me to remove it. One side effect of this PR is that the CanvasKit-related code isn't tree-shaken out. That results in an increase of 14kb (~2.1%) in flutter_gallery's release build. I personally think this is fine because we are moving to a model where we use both html and canvaskit backends interchangeably.

@ferhatb
Copy link
Contributor

ferhatb commented Mar 11, 2020

@mdebbar @hterkelsen : Can we defer load canvaskit code to eliminate -2.1% regression. Our target for Q1 is to reduce 10% and expecting CanvasKit to grow over the next 3-4 months.

@mdebbar
Copy link
Contributor Author

mdebbar commented Mar 11, 2020

@ferhatb I can revert the canvaskit flag back to being a const, which will tree-shake our canvaskit-related code for users who don't enable canvas kit.

This increase in code size won't affect people who enable canvas kit because they are already including canvaskit code in their bundles. But it will affect today's default mode which doesn't enable canvaskit.

@ferhatb
Copy link
Contributor

ferhatb commented Mar 11, 2020

@mdebbar : Looking towards future, we want initial bundle to not contain canvaskit (treeshaken) , but then defer load canvaskit dart code + wasm. Yes i would revert canvaskit flag for now unless its easy to defer dart code and lazily load even for default.

WebExperiments._();

/// Experiment flag for using the Skia-based rendering backend.
bool get useSkia => _useSkia ?? false;
Copy link
Contributor

Choose a reason for hiding this comment

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

While you're here, could you please rename this to useCanvasKit? We're consolidating on the name "CanvasKit". Keep the old FLUTTER_WEB_USE_SKIA flag for now. Changing that would be a breaking change for the framework tests.

for (final String name in message.keys) {
final bool enabled = message[name];
switch (name) {
case 'useSkia':
Copy link
Contributor

Choose a reason for hiding this comment

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

This name can also be useCanvasKit since nothing uses it yet.

@harryterkelsen
Copy link
Contributor

When in the lifecycle do we expect for the enable_experiments messages to be passed? I don't think it will work to enable CanvasKit after the app has started running: we look at the canvaskit flag while initializing to switch to the CanvasKit based font-loading and also download the CanvasKit WASM

@yjbanov
Copy link
Contributor

yjbanov commented Mar 12, 2020

@hterkelsen

When in the lifecycle do we expect for the enable_experiments messages to be passed? I don't think it will work to enable CanvasKit after the app has started running: we look at the canvaskit flag while initializing to switch to the CanvasKit based font-loading and also download the CanvasKit WASM

I totally missed that. Good catch! Can we use JS-interop instead of platform messages? JS-interop is synchronous so we can guarantee the sequence of events w.r.t. to the start-up lifecycle.

@mdebbar mdebbar requested a review from yjbanov March 13, 2020 20:21
@mdebbar mdebbar changed the title [web] Introduce platform message to enable experiment flags on web [web] Introduce js interop to enable experimental flags on web Mar 16, 2020
domRenderer;

// Calling this getter to force the [WebExperiments] instance to be created.
webExperiments;
Copy link
Contributor

Choose a reason for hiding this comment

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

domRenderer is actually a bad pattern to mimic. We had several bugs due to unpredictable initialization order. Consider using the ensureInitialized pattern from the various "Binding" classes we have.

/// certain experiments at runtime without the need to access engine internals.
class WebExperiments {
WebExperiments._() {
js.context['_flutter_internal_update_experiment'] = updateExperiment;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised this works without jsify or allowInterop or some such 🤔

}

/// Experiment flag for using canvas-based text measurement.
bool get useCanvasText => _useCanvasText ?? false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does allowing null help with anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. In tests, we set the flag to a specific value (true or false), then we set it back to null when the test is done. The value null means "use the default value".

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

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

LGTM modulo some nits.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants