Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance comparison #34

Open
uc-apa opened this issue Mar 3, 2020 · 6 comments
Open

Performance comparison #34

uc-apa opened this issue Mar 3, 2020 · 6 comments

Comments

@uc-apa
Copy link

uc-apa commented Mar 3, 2020

The simplicity and usage of this plugin are very effective and I have looked into both the packages, the division and styled_widget. But I am not sure which has more performance as there are method calling for each and every style. Calling methods for each single style may affect performance as compared to plain dart code. Kindly guide me in the right direction. Which way will be more performant/fast executing, the devision way, styled_widget way or plain dart code as provided by the framework itself for a large scale mobile app. If there would be an option to apply multiple styles in single method call then it would be great.

@ReinBentdal
Copy link
Owner

This has been a concern for me as well. Would be interesting to to a proper performance test to see the actual difference.
Plan Dart/Flutter will always be faster, given you write your code reasonable efficient. This will be the same as C++ will be more performant than JavaScript because it's more low level, again given you write the code efficient.
I think styled_widget is more performant than division since the widgets are more splited but I'm not quite sure.
If you define a widget as final (if you know it won't change), the methods will only be called once which will only be a potential performance issue on first render.

I have build a couple bigger projects myself with styled_widget and I haven't noticed a performance issue so far

@ReinBentdal
Copy link
Owner

There is already an option to apply multiple styled using for example decoration and constraints

@ghost
Copy link

ghost commented Mar 10, 2020

Awesome project. Is this library production ready?

@ReinBentdal
Copy link
Owner

It depends on what you mean on production ready. Feature wise the package is good but it is still subject to change.
I am working on version 0.2.0 which will have a couple of breaking changes which I am making to improve performance.

@ghost
Copy link

ghost commented Mar 13, 2020

@ReinBentdal that's ok. We can freeze the library on this version. What I'm asking is that if I could use it in production since this package helps write maintainable UI code.

@ReinBentdal
Copy link
Owner

I see, i would say yes. I would recomend using the newest version 0.2.0, since it has some performance improvements.

I would not recomend using the Text and icon extensions heavily since each method has to initiate a new Text widget. For example i would not write this:

Text('some text')
  .bold()
  .fontSize(24)
  .padding(all: 24)
  .backgroundColor(Colors.red)

And instead to something like this:

final TextStyle textStyle = TextStyle(
  fontSize: 24,
  fontWeight: FontWeight.bold,
);

Text('some text', style: textStyle)
  .padding(all: 24)
  .backgroundColor(Colors.red)

And if you are applying more than one styles originating from the DecoratedBox widget:

Text('some text') // do`nt
  .backgroundColor(Colors.red)
  .borderRadius(all: 24)

Text('some text') // do
  .decorated(
    color: Colors.red,
    borderRadius: BorderRadius.circlular(24)
  )

What i am saying here can be summed up as: The package is not a replacement of the current way of building widgets with flutter, but a complimentary tool. When used right i think its a very useful.

I (or someone else) should probably spend some time improving the documentation to address these things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants