Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
5b6444f3
Unverified
Commit
5b6444f3
authored
Feb 02, 2021
by
Yegor
Committed by
GitHub
Feb 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[web] benchmark and optimize defaultTargetPlatform (#75037)
parent
4ba26191
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
6 deletions
+41
-6
bench_default_target_platform.dart
...benchmarks/lib/src/web/bench_default_target_platform.dart
+30
-0
web_benchmarks.dart
dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart
+2
-0
_platform_web.dart
packages/flutter/lib/src/foundation/_platform_web.dart
+9
-6
No files found.
dev/benchmarks/macrobenchmarks/lib/src/web/bench_default_target_platform.dart
0 → 100644
View file @
5b6444f3
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/foundation.dart'
;
import
'recorder.dart'
;
/// Benchmarks the performance of the [defaultTargetPlatform] getter.
///
/// The getter relies on the expensive `window.matchMedia` and if not properly
/// cached can cause performance issues.
class
BenchDefaultTargetPlatform
extends
RawRecorder
{
BenchDefaultTargetPlatform
()
:
super
(
name:
benchmarkName
);
static
const
String
benchmarkName
=
'default_target_platform'
;
/// A dummy counter just to make sure the compiler doesn't inline the
/// benchmark and make it a no-op.
int
counter
=
0
;
@override
void
body
(
Profile
profile
)
{
profile
.
record
(
'runtime'
,
()
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
counter
+=
defaultTargetPlatform
.
index
;
}
},
reported:
true
);
}
}
dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart
View file @
5b6444f3
...
...
@@ -15,6 +15,7 @@ import 'src/web/bench_build_material_checkbox.dart';
import
'src/web/bench_card_infinite_scroll.dart'
;
import
'src/web/bench_child_layers.dart'
;
import
'src/web/bench_clipped_out_pictures.dart'
;
import
'src/web/bench_default_target_platform.dart'
;
import
'src/web/bench_draw_rect.dart'
;
import
'src/web/bench_dynamic_clip_on_static_picture.dart'
;
import
'src/web/bench_mouse_region_grid_hover.dart'
;
...
...
@@ -37,6 +38,7 @@ const bool isCanvasKit = bool.fromEnvironment('FLUTTER_WEB_USE_SKIA', defaultVal
/// When adding a new benchmark, add it to this map. Make sure that the name
/// of your benchmark is unique.
final
Map
<
String
,
RecorderFactory
>
benchmarks
=
<
String
,
RecorderFactory
>{
BenchDefaultTargetPlatform
.
benchmarkName
:
()
=>
BenchDefaultTargetPlatform
(),
BenchBuildImage
.
benchmarkName
:
()
=>
BenchBuildImage
(),
BenchCardInfiniteScroll
.
benchmarkName
:
()
=>
BenchCardInfiniteScroll
.
forward
(),
BenchCardInfiniteScroll
.
benchmarkNameBackward
:
()
=>
BenchCardInfiniteScroll
.
backward
(),
...
...
packages/flutter/lib/src/foundation/_platform_web.dart
View file @
5b6444f3
...
...
@@ -10,13 +10,16 @@ platform.TargetPlatform get defaultTargetPlatform {
// To get a better guess at the targetPlatform we need to be able to reference
// the window, but that won't be available until we fix the platforms
// configuration for Flutter.
platform
.
TargetPlatform
result
=
_browserPlatform
();
if
(
platform
.
debugDefaultTargetPlatformOverride
!=
null
)
result
=
platform
.
debugDefaultTargetPlatformOverride
!;
return
result
;
return
platform
.
debugDefaultTargetPlatformOverride
??
_browserPlatform
;
}
platform
.
TargetPlatform
_browserPlatform
(
)
{
// Lazy-initialized and forever cached current browser platform.
//
// Computing the platform is expensive as it uses `window.matchMedia`, which
// needs to parse and evaluate a CSS selector. On some devices this takes up to
// 0.20ms. As `defaultTargetPlatform` is routinely called dozens of times per
// frame this value should be cached.
final
platform
.
TargetPlatform
_browserPlatform
=
()
{
final
String
navigatorPlatform
=
html
.
window
.
navigator
.
platform
?.
toLowerCase
()
??
''
;
if
(
navigatorPlatform
.
startsWith
(
'mac'
))
{
return
platform
.
TargetPlatform
.
macOS
;
...
...
@@ -41,4 +44,4 @@ platform.TargetPlatform _browserPlatform() {
return
platform
.
TargetPlatform
.
linux
;
}
return
platform
.
TargetPlatform
.
android
;
}
}
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment