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

Css-Cache for the ThemeGenerator #2103

Closed
FStolte opened this issue Mar 25, 2021 · 6 comments
Closed

Css-Cache for the ThemeGenerator #2103

FStolte opened this issue Mar 25, 2021 · 6 comments
Labels
Type: Feature ⚙ Request or idea for a new feature.
Milestone

Comments

@FStolte
Copy link
Contributor

FStolte commented Mar 25, 2021

We recently started using the Blazorise Theme in one of our projects to get our custom primary color into the Blazorise css (for the Stepper component). Now, we noticed a performance impact of using the Theme which slowed down initial site loading from about 600ms to 1.7s. This is on Server-side Blazor, btw.

Since likely most projects will only use a few different Themes, or even just one, I think it might be useful to implement a cache for the ThemeGenerator. If the same Theme is passed several times to the generator, it should not be necessary to generate the css again every time. If this performance impact is not just on our side, then a cache could bring a nice performance boost to the framework.

Of course this only really helps Server-side Blazor, since Blazor Webassembly would have to generate each Theme for each user once, anyway.

@stsrki
Copy link
Collaborator

stsrki commented Mar 25, 2021

It all depends on where the actual problem is. Does the generator takes too much time to build or does it takes slow to read HTML once the styles are loaded? I think I can easily cache the built styles. It's just a matter of few boolean flags. Hope it will help a little.

@stsrki
Copy link
Collaborator

stsrki commented Mar 25, 2021

@FStolte Are you sure we need caching? I'm testing to see how many times Blazor could re-render ThemeProvider and re-generate the theme and I found it only happens once on the app start. Later when I navigate to any page it still doesn't re-generate. Unless I specifically call ThemeHasChanged().

@FStolte
Copy link
Contributor Author

FStolte commented Mar 25, 2021

I think you might've misunderstood me. In a single session, the generation only happens once in the beginning as you say. But it happens once for every session, so for everyone accessing the page, the first load is delayed. I was talking about caching the css across sessions in a singleton service, so that it ideally only needs to happen once each time the app is deployed (for Server-side Blazor, of course).

@stsrki
Copy link
Collaborator

stsrki commented Mar 25, 2021

Ahhh that. Well, it is working as expected. Remember, even if you have 100 users, one of those users can still choose to have a different theme color. That is, if you have a way to choosing a theme in your app.

The only thing I can do is to maybe move a generator into a service class that can be injected through the DI. That way you could re-register it as singleton maybe.

@FStolte
Copy link
Contributor Author

FStolte commented Mar 25, 2021

"even if you have 100 users, one of those users can still choose to have a different theme color"
That's why I was thinking of basically storing the css for every unique Theme if it was requested once, with an upper limit on how many Themes are cached totally. If the same Theme is requested twice, we don't need to re-generate it as long as it is still in the cache. So if 98 of those 100 users have the default theme and 2 picked custom ones, 97 users could still benefit from having the default theme cached.

I understand that this might not be a priority for you, but would you be open to a PR from me about this topic?

@stsrki
Copy link
Collaborator

stsrki commented Mar 25, 2021

Let the code speaks for itself :) Yes, if possible open a new PR and we'll see how it goes.

Don't forget to read our CONTRIBUTING https://github.com/stsrki/Blazorise/blob/master/CONTRIBUTING.md#branch-organization guidelines.

@stsrki stsrki mentioned this issue Apr 26, 2021
@stsrki stsrki added the Type: Feature ⚙ Request or idea for a new feature. label Apr 26, 2021
@stsrki stsrki added this to the 0.9.4 milestone Apr 26, 2021
@stsrki stsrki closed this as completed Apr 26, 2021
@stsrki stsrki moved this to ✔ Done in Development Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature ⚙ Request or idea for a new feature.
Projects
Archived in project
Development

No branches or pull requests

2 participants