Exercising Compose for Desktop and Compose for Web (Canvas)

Overview

Compose Counting Grid

A simple application to check Compose for Desktop and Compose for Web (Canvas) drawing speeds when drawing grids (or tables) with larger numbers of cells.

Implementation differences:

  • The desktop application uses a window-sized canvas. Compose scrollbars appear if necessary.
  • The web application uses a content-sized (window) canvas. The browser's scrollbars appear if necessary.

Initial Scene

Initial Scene

Desktop with Recomposition Highlighting

Desktop with Highlighting

Desktop High-Frequency Update (Top Row Only)

  • This animated GIF ⚠️ not suitable for people with photosensitive epilepsy ⚠️ demonstrates increasing FPS as the window shrinks: Animation with high-frequency updates.

    This effect appears with the desktop application, not the web application.

How It Operates

Given a grid of cells: Choose a random cell. Increase its single-digit count. Repeat.

Unless pausing is enabled, updates will be drawn as fast as possible. The desktop application will even go beyond your display's vsync frequency (which Compose/Skia normally would not do, as it makes no sense other than to check the speed).

How To Build And Run

JVM desktop application: ./gradlew run

Browser application: ./gradlew frontendJsBrowserProductionRun (requires some patience for bundles to load)

Currently, frontendJsBrowserDevelopmentRun cannot be used as the development bundle does not build due to JetBrains/compose-jb#2255.

What To Try

  • Try everything without animations first.
  • Resize the window so that only the top row of counters is visible.
  • Highlight re-compositions.
  • Toggle "Force top-level recomposition".

Remarks

  • This application does not simulate any real-world scenario as it uses a very simple layout with fixed-size cells.
  • Compose for Web on Canvas is at an experimental stage. This application uses funky tricks to fit the canvas to its content size.

Findings

Observations:

  • Larger grids are slower.
  • Grids with fewer cells containing text are faster (choose top-row updates only, then clear the grid).

    Note that empty cells don't have a Text component.

  • Grids with more cells scrolled out of view (applies to desktop only) are faster.
  • Top- or row-level layout and recomposition accounts for about 10% of total performance (try forcing top-level and/or row-level recompositions, check the profiler's flame graph). In these scenarios, redrawing dominates performance.
  • Cell-level recomposition is expensive. On desktop, it cuts the frame rate by 50% (25x25 grid) or even by 70% (50x50 grid), and makes the profiler's flame graph show significant recomposition and layout activity. Redrawing is still relevant, but less so. On the browser, the frame rate drops by 80% (25x25 grid) or more.

Conclusions:

  • Currently, it appears that the entire (window) canvas is redrawn on every frame. Once JetBrains/skiko#53 is fixed and only updated parts are redrawn, expect significant performance increases.
  • Drawing time increases with the number of visible layout nodes.
  • Still, Compose for Desktop seems pretty fast.
  • Compose for Web/Canvas is significantly slower than desktop (I have seen roughly a factor of 3), but it would also use just 10% for layout and top/row-level recomposition. Depending on the use case, even at this early stage Web/Canvas could still be fast enough.
  • It pays to avoid recompositions which affect large numbers of composables.

Changes

2022-08-23
  • Added options to force row-level and cell-level recompositions. Revised conclusions regarding recomposition and layout impact.
  • Improved UI responsiveness when toggling options for recomposition highlighting and animations.
2022-09-02
  • Redesigned Web/Canvas integration thanks to @langara
You might also like...
Row Coloumn Box Compose Constraint Layout Modifier.xyz Animator Tween animation MutableState Creating custom composable Corners Canvas LaunchedEffect
Row Coloumn Box Compose Constraint Layout Modifier.xyz Animator Tween animation MutableState Creating custom composable Corners Canvas LaunchedEffect

Row Coloumn Box Compose Constraint Layout Modifier.xyz Animator Tween animation MutableState Creating custom composable Corners Canvas LaunchedEffect

⌨️ A tool that gives you a massive head start when building Compose Desktop apps. It saves you from time-consuming setup and configuration
⌨️ A tool that gives you a massive head start when building Compose Desktop apps. It saves you from time-consuming setup and configuration

💻 create-compose-app A tool that gives you a massive head start when building Compose based apps. It saves you from time-consuming setup and configur

💻 A Compose Desktop project template with MVVM, Dagger, Decompose, tests, and more...
💻 A Compose Desktop project template with MVVM, Dagger, Decompose, tests, and more...

compose-desktop-template A compose desktop project template with MVVM, Dagger, Decompose and more ✨ Demo What's included? Architecture (MVVM) with And

⌨️ A tool that gives you a massive head start when building Compose Desktop apps. It saves you from time-consuming setup and configuration
⌨️ A tool that gives you a massive head start when building Compose Desktop apps. It saves you from time-consuming setup and configuration

💻 create-compose-app A tool that gives you a massive head start when building Compose based apps. It saves you from time-consuming setup and configur

JetBrains style controls and UI for Compose Desktop
JetBrains style controls and UI for Compose Desktop

JetBrains UI Kit for Compose Desktop JetBrains style controls and UI for Compose Desktop. Quick Start 1. Add dependency dependencies { implementat

A compose desktop project template with MVVM, Dagger, Decompose and more
A compose desktop project template with MVVM, Dagger, Decompose and more

compose-desktop-template A compose desktop project template with MVVM, Dagger, D

A simple Snake application to demonstrate the use of Compose for Desktop platform with Kotlin
A simple Snake application to demonstrate the use of Compose for Desktop platform with Kotlin

Snake App using Compose for Desktop A simple Snake desktop application to demonstrate the use of Compose UI toolkit for Desktop platform with Kotlin.

🔖 A Quotes Application built to Demonstrate the Compose for Desktop UI
🔖 A Quotes Application built to Demonstrate the Compose for Desktop UI

🔖 JetQuotes A Quotes Application built to Demonstrate the use of Jetpack Compose for building declarative UI in Desktop. Made with love ❤️ by Spikeys

A Sudoku game for Android & Desktop written with Jetpack Compose Multiplatform
A Sudoku game for Android & Desktop written with Jetpack Compose Multiplatform

🚀 Compose Arcade A sample Kotlin Multiplatform Compose Sudoku app for Android & Desktop. Most code is shared between Android & Desktop using Kotlin M

Comments
  • Refactor canvas configuration

    Refactor canvas configuration

    I experimented a bit with setting up web canvas with skia content in a different way. Auto resizing is based on snapshot state in this version. I find it simpler, but must admin I'm somewhat confused by lifecycle details between html canvas and skia layer, so I guess my version is "more correct" but still not ideal. I left your version too for comparison. Feel free to pull it if you like it.

    opened by langara 2
Owner
null
Jetpack Compose Boids | Flocking Insect 🐜. bird or Fish simulation using Jetpack Compose Desktop 🚀, using Canvas API 🎨

?? ?? ?? Compose flocking Ants(boids) ?? ?? ?? Jetpack compose Boids | Flocking Insect. bird or Fish simulation using Jetpack Compose Desktop ?? , usi

Chetan Gupta 38 Sep 25, 2022
Briar-desktop - A desktop program for Briar, bringing secure messaging to your desktop and mobile devices

Briar Desktop A desktop program for Briar, bringing secure messaging to your des

Briar Project 16 Dec 17, 2022
Welcome Fruit Ninja 🥝 on Jetpack Compose Desktop 🚀, using Canvas API 🎨

Compose-Fruit-Ninja ?? Welcome Fruit Ninja on Jetpack Compose Desktop ?? , using Canvas API ?? Featured on jetc-dev How to Run From gradle tab from ri

Chetan Gupta 54 Nov 2, 2022
Alien invasion 👾 gane is back! this time specially on Jetpack Compose Desktop 🚀, using Canvas API 🎨

Compose Space-Invaders ?? Alien invasion ?? is back! this time specially on Jetpack Compose Desktop ?? , using Canvas API ?? Featured on Compose Diges

Chetan Gupta 58 Aug 6, 2022
Test-compose-for-desktop - Hello World in Compose for Desktop

Testing Run from command line: ./gradlew run Regular build: ./gradlew packageUb

Sebastian 3 Sep 20, 2022
Snake-compose-for-desktop - Snake Game - implemented using Compose for Desktop

A Snake game, built with Compose for Desktop snake-compose-for-desktop is my imp

gnu 5 Feb 17, 2022
A desktop code editor app using Jetpack Compose for Desktop and IntelliJ Platform

Compose Code Editor A desktop code editor app using Jetpack Compose for Desktop and IntelliJ Platform. Project Structure The code is contained in the

Alex 73 Dec 19, 2022
💻 A cross-platform desktop application to identify libraries used inside an android application. Made possible by Compose Desktop ⚡

?? stackzy A desktop app to analyse APK. Built using Compose desktop ✨ Demo Watch demo ??️ Usage Show usage ?? Install Platform Download Status Linux

theapache64 876 Dec 24, 2022
This repo is to demonstrate the jetpack compose 's canvas api's usage and creating an icon pack using the basic functions.

Jetpack Compose Canvas API Demo App We all know that Jetpack Compose has now reached the 1.0.0 release milestone. This is a huge change we can say for

vikas kumar 32 Dec 15, 2022
Resume of Louis CAD, made with Jetpack Compose. Supports the Web, Desktop, and Android.

ResumeComposition What This project is the source code of the resume/CV of Louis CAD. The latest PDF export is available here, it is ready to print. H

Louis CAD 22 Aug 14, 2022