GithubHelp home page GithubHelp logo

Comments (4)

Malarg avatar Malarg commented on July 28, 2024 2

How to use DevTools:

2022-09-28.09.45.07.mov

from flutter-code-editor.

Malarg avatar Malarg commented on July 28, 2024

Flutter code editor performance research

Source data

web-renderer: canvaskit
build mode: profile (release mode misuse here because compiler hide methods names, so we can’t recognize them in devtools)
language: python
theme: monokai-sublime
code: copy-pasted several times MinimalWordCount example. (2058 rows total)
testing actions: change cursor position and add symbol

Changing cursor position took about 545 ms for 2 largest events. Call stack of both of them mostly belongs to flutter source code, so we can’t handle it.
Image

Adding symbol took about 847 ms for 2 largest events. We can work with about 10% of this time, another one flutter uses for layouting.
Image

What already has been tried:

  1. Tried to find custom textfield for our requirements
  2. Tried to change current textfield properties for better performance

Possible ways to improve

  1. Splitting one big textfield on textfields list
  2. Set to textfield just visible text with extra viewport at top and bottom for smooth scrolling

from flutter-code-editor.

alexeyinkin avatar alexeyinkin commented on July 28, 2024

Highlighted is the current overhead of the comment parser, the foldable block parser, and other add-ons of ours. Hence we don't plan to optimize them. Improvements must be done in the Flutter part if we want them.

image

Keeping this open.

from flutter-code-editor.

yescorp avatar yescorp commented on July 28, 2024
  • Seems like I duplicated this issue here #170

Little summary from the "discussion" from there.
TextField uses TextPainter inside, which takes a long time to layout if the text is huge. As I found, there is no way to affect to this.

TextPainter.layout() -> expensive
TextPainter.paint() -> cheap (can only be called after layout)

If we try to use CustomPaint with caching TextPainters to make efficient use of them, it still scales quickly enough to become laggy at 700 lines of code.

Using ListView.builder to display only visible lines doesn't work for some reason.
Even though ListView.builder documentation says that it builds the widgets on demand, that is not what I actually experienced when testing it. It was even more laggy than CustomPaint approach.

Finally, the solution that is similar to ListView.builder -> CustomScrollView with slivers.
This actually builds only those widgets, that are currently visible on the ViewPort. I believe this will allow us to reach maximum performance, as well as a whole bunch of new opportunities:

  • Drawing indentation indicators
  • Drawing errors indicators on the text position
  • Drawing anything along with the text. (like folded block indicators, helper comments like flutter widgets etc.)
  • Expose API for painting on the TextField so that users can do whatever they want on it.

Although, I also like the solution proposed by @Malarg, to split the TextField into many TextFields. That will definitely work.
But that implementation is also hard, while not providing other benefits apart from performance.

from flutter-code-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.