Comments (7)
An improvement:
internal val labelTypography: Typography
@Composable
get() {
val ff = helveticaNeueFontFamily // call getter only once, so the `fetch` wan't happen every time
return Typography(
displayLarge = MaterialTheme.typography.displayLarge.copy(fontFamily = ff),
displayMedium = MaterialTheme.typography.displayMedium.copy(fontFamily = ff),
displaySmall = MaterialTheme.typography.displaySmall.copy(fontFamily = ff),
headlineLarge = MaterialTheme.typography.headlineLarge.copy(fontFamily = ff),
headlineMedium = MaterialTheme.typography.headlineMedium.copy(fontFamily = ff),
headlineSmall = MaterialTheme.typography.headlineSmall.copy(fontFamily = ff),
titleLarge = MaterialTheme.typography.titleLarge.copy(fontFamily = ff),
titleMedium = MaterialTheme.typography.titleMedium.copy(fontFamily = ff),
titleSmall = MaterialTheme.typography.titleSmall.copy(fontFamily = ff),
bodyLarge = MaterialTheme.typography.bodyLarge.copy(fontFamily = ff),
bodyMedium = MaterialTheme.typography.bodyMedium.copy(fontFamily = ff),
bodySmall = MaterialTheme.typography.bodySmall.copy(fontFamily = ff),
labelLarge = MaterialTheme.typography.labelLarge.copy(fontFamily = ff),
labelMedium = MaterialTheme.typography.labelMedium.copy(fontFamily = ff),
labelSmall = MaterialTheme.typography.labelSmall.copy(fontFamily = ff),
)
}
Also, give 1.7.0-dev1721
a try. It has this change: #4893 which might help a bit. (using kotlin = "2.0.20-Beta2")
Also, using rel=preload
for the resources such as fonts might be beneficial: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload
from compose-multiplatform.
So, my final report:
Using rel="preload"
and storing the fontFamiliy as a val inside the composable function improves significantly the performance. But combining it with 1.7.0-dev1721
removes any font lag.
Tested on the slowest physical device I have:
- Allwinner T8100 (T8100C045298)
- Android 10 API 29
- Chrome 126.0.6478.71
- Power save mode ON
No optimizations:
no-opt.mp4
Optimizations + 1.6.11:
1.6.11.mp4
Optimizations + 1.7.0-dev1721:
1.7.0-dev1721.mp4
@eymar I think we can close this issue and possible reopen if next Beta or RC breaks this, but I believe it would be very beneficial that this optimisations hints (especially the html one) could be documented.
from compose-multiplatform.
This is an example from a different app:
<link rel="preload" href="./composeResources/username.composeapp.generated.resources/font/FiraMono-Regular.ttf" as="fetch" type="font/ttf" crossorigin/>
from compose-multiplatform.
Anything that involves network requests (including fonts loading) will take some time to complete. Therefore, it can be barely noticeable if the connection is fast and the latency is low. But If the connection is not so fast, the UX is indeed affected.
What are the options to improve the situation:
- There is an experimental Local Fonts API available only in Chrome: https://developer.mozilla.org/en-US/docs/Web/API/Local_Font_Access_API - so you might avoid the network request. Not all fonts will be available though (depends on the system).
- Alternatively, it's worth to preload the fonts during the app initialization - before displaying the content.
Could you please point to the place in code where you currently do Fonts loading?
from compose-multiplatform.
The tests were conducted in the same network and the fonts are local resources in the project, therefore I believe the problem remains with hardware and possible code optimisations.
I'm using composeResources
so I believe the loading operations are automatic:
from compose-multiplatform.
Nice tips, thanks!
val ff = helveticaNeueFontFamily // call getter only once, so the `fetch` wan't happen every time
✅ - this one shows significant improvements
Also, give
1.7.0-dev1721
a try. It has this change: #4893 which might help a bit. (using kotlin = "2.0.20-Beta2")
✅
Also, using
rel=preload
for the resources such as fonts might be beneficial: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload
Where should I apply this one? The only <link>
I have is <link rel="icon" type="image/x-icon" href="icon.png">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Who'sNext</title>
<link rel="icon" type="image/x-icon" href="icon.png">
<script type="application/javascript" src="skiko.js"></script>
<script type="application/javascript" src="browserApp.js"></script>
<meta content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=3, user-scalable=yes" name="viewport">
</head>
<body>
<canvas id="WhosNext"></canvas>
</body>
</html>
from compose-multiplatform.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
from compose-multiplatform.
Related Issues (20)
- [1.7.0-alpha01] GraphicsLayer do not seems to like being drawn multiple times HOT 3
- MacOS Notarize App with Native Library Failed Error 65 HOT 4
- [1.7.0-alpha01] Moving after initiating a click cancels it HOT 2
- Preview in commonMain? HOT 2
- [1.7.0-alpha01] Cannot change attributes of dependency configuration ':debugFrameworkIosArm64' after it has been resolved HOT 9
- I have an issue with a common ViewModel and navigation in my Compose Multiplatform application HOT 3
- Ios crash while using textMeasurer.measure inside Dispatchers.Default HOT 17
- CompositionLocalProvider related RuntimeError: illegal cast HOT 7
- Compose navigation crash v2.8.0-alpha08 (UnsatisfiedLinkError) HOT 5
- Support common `org.jetbrains.compose.ui.tooling.preview.Preview` in IDEA and Android Studio HOT 14
- ShadowJar Executable HOT 2
- Error: self-signed certificate in certificate chain HOT 5
- Improved window sizing API (Windows) HOT 3
- iOS Keyboard Broken with `readOnly` will show/hide in loop HOT 13
- iOS: ModalBottomSheet can't ignore safeArea HOT 2
- Unable to run tests using Multiplatform Resources HOT 2
- Make AnnotatedString.Companion.fromHtml available to multiplatform HOT 3
- [WASM] Custom Font Text flickering from tofu to the actual text with the right font HOT 3
- Previewing fails with AssertionError: Data is too big HOT 1
- Important: please use YouTrack for bugs and feature requests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compose-multiplatform.