Git Product home page Git Product logo

Comments (7)

texus avatar texus commented on August 21, 2024

I agree that the following code would be more graceful that with the copy, but I don't really see a reason for a separate theme manager to be created.
auto button1 = Button::create(filename, section);
auto button2 = Button::create(filename, section);

The extra step to create the theme manager looks unneeded to me, unless you have another reason for it other than performance. If performance is the only reason then I can just as well cache the theme file internally.

But I am planning to review the widget creating code again, so I will keep this idea in mind.
A theme manager could perhaps be useful to make all widgets depend on one theme so that the theme of all widgets can be changed with just one line of code.

But this is all going to be for next year.

from tgui.

soarqin avatar soarqin commented on August 21, 2024

Yeah, using a theme cache provides better performance without any interface changes, it is a great idea for doing such optimizations in minor versions.

from tgui.

texus avatar texus commented on August 21, 2024

I will do some tests tomorrow to see if the perfomance difference is really that big.
I am not planning to add a cache if the difference is hardly noticable.

from tgui.

soarqin avatar soarqin commented on August 21, 2024

How big the performance improves depends on how big theme files are and how often to create the widgets dynamically, so I think it is a MUST-DO feature for some special scene(like create large amount of widgets in a window without using copy)

from tgui.

texus avatar texus commented on August 21, 2024

I just did some speed tests, and the caching won't be needed to make recreating the widget faster compared to copying it.

The tests have been done with 16.000 widgets (10.000 widgets of each of the 16 used types).
The speed difference with the white-theme is expected since it doesn't load or parse any files.

  • Creating widgets with built-in white theme: 6.25 seconds
  • Creating widgets with black theme: 31 seconds
  • Copying widgets: 36.5 second

So it looks like copying is even slower than recreating the widget. I will look for a reason later.

from tgui.

texus avatar texus commented on August 21, 2024

Ok, these numbers don't really represent much. Some widgets must be taking a lot more time than they should.

New test with 100.000 buttons:
Creating with White theme: 3.6 seconds
Creating with Black theme: 8 seconds
Copying: 2.7 seconds

from tgui.

texus avatar texus commented on August 21, 2024

Ok, caching seems to have a significant impact (much more than I expected).
I will be adding the caching in both v0.6.6 and v0.7-dev.

Again, for 100.000 buttons:
Copying buttons: 1.25s
Cached theme file: 3.5s
Section at beginning of file: 5.45s
Section at end of file: 14.3s

So I notice a few things:

  • Copying is still more than twice as fast as reloading the button (nothing can be done about that)
  • It takes only 0,02 to 0,05 milliseconds to create a button if one was already loaded before
  • The 5.45s is equivalent with the 8s earlier. I am using a different version, but that means that the new callback system in v0.7-dev will make creating widgets slightly slower.

I am going to close this issue (once it is implemented) since I don't expect to be writing a ThemeManager soon and I already have another issue reminding me that the entire loading code should be reviewed.
Thanks for making the suggestion though, I never knew that parsing these theme files took so long.

PS: All times were measured in debug mode. When using TGUI it should be much faster.

from tgui.

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.