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

Compilation bottlenecked on StringSplitter#dispatcher #139

Closed
stanhu opened this issue May 1, 2019 · 2 comments
Closed

Compilation bottlenecked on StringSplitter#dispatcher #139

stanhu opened this issue May 1, 2019 · 2 comments

Comments

@stanhu
Copy link

stanhu commented May 1, 2019

I profiled an initial rendering of a Rails page that took 2 seconds initially. It looks like a significant amount of time is spent in StringSplitter#dispatcher, which looks like it's calling Kernel#class from https://github.com/judofyr/temple/blob/7987ab67af00a598eb3d83192415371498a0f125/lib/temple/mixins/dispatcher.rb#L65:

image

I'm not sure what it's doing here, but I wonder how we can optimize this?

@k0kubun
Copy link
Owner

k0kubun commented May 1, 2019

First of all, compilation speed is a trade-off with rendering speed. It should not be terribly slow but at least it's not Hamlit's focus. If you're concerned about compilation time more, you may want to use haml.gem instead.

For your original question, Hamlit::StringSplitter is inheriting Temple::Filter and the #dispatcher is implemented in Temple::Filter as you pointed. The main code seems to be tree.compile.gsub("\n", "\n ") and I'm actually not sure why it needs to check class in that place. If we were able to remove that from the method body, it would be nice (but not sure if we can). The filter in Hamlit is splitting an interpolated string literal in Haml attributes to reduce the number of string concatenations on rendering.

As I don't want to remove this filter from Hamlit, You may want to open this issue in Temple repository to have some insights from other maintainers. Thanks for investigating the bottleneck of Hamlit compilation :)

@stanhu
Copy link
Author

stanhu commented May 1, 2019

@k0kubun Thanks for your response and this gem! I've opened judofyr/temple#124 to follow up.

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

No branches or pull requests

2 participants