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

Speed benchmarks #325

Closed
codesections opened this Issue Jul 1, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@codesections
Copy link
Contributor

codesections commented Jul 1, 2018

I am considering switching from Hugo to Gutenberg (the big draw is the sane template system—thanks so much for that!). I'm also planning to write about the comparison between the two.

As part of that process, I've been running benchmarks on my site using hyperfine. I was expecting that Gutenberg would be faster, since Rust is generally a bit faster than Go. However, to my surprise, Gutenberg took nearly 3 times as long to build my (small) site: 151.8 ms vs Hugo's 57.8 ms. Based on that, I have a few questions.

  • Is this typical, or is my site getting odd results? I can't think of any reason my site (www.codesections.com) should be atypical, but thought I'd ask.
  • If this is typical, do you know what causes it? I thought it might have to to with Hugo's incremental rebuilds, but that doesn't seem to be it—deleting the built files first doesn't have any effect. Does it come from the templating system? Or is Gutenberg less paralel?
  • Relatedly, do you have any plans for improving speed? If it is about parallelism, to you plan to implement anything along those lines?

Thanks again for your work on this project. I really like it, an may well switch even if it really isn't as fast. But I wanted to give you a chance to weigh in before I write a post saying it's much slower than Hugo at the moment.

@Keats

This comment has been minimized.

Copy link
Collaborator

Keats commented Jul 1, 2018

Do you have a sample repo to see the difference? Is that the full build or only the rebuild time?

I haven't spent that much time improving performances as my sites are in the ms range as well and didn't feel the need to optimize more so there are quite a few clone() around the codebase. Another possible explanation for the speed difference for the site is that Tera needs to serialize the context to JSON and I don't believe the Go template engine does any kind of serialization. The syntax highlighting that Hugo uses is also way simpler than Gutenberg which is actually using the same syntax highlighting as Sublime Text and therefore slower (rendering markdown with highlighting is about 4x slower than without in Gutenberg).

Almsot everything in Gutenberg is already parallelised so I think so the best improvement would come from reducing the number of clones.

I'm not planning to work on any perf improvement for a bit as there are still important features missing like i18n that are way more needed than gaining a few ms.

@codesections

This comment has been minimized.

Copy link
Contributor

codesections commented Jul 1, 2018

Thanks for the reply. I don't (yet) have a sample repo for a Gutenberg version of the site, since I'm still working on converting it. I'll update this thread when I do. The Hugo version of the repo is at codesections/codesections.

After a bit more testing, it looks like you're right about the syntax highlighting being a main culprit, though it looks like creating the search index contributes even more. I've listed out the times I've gotten below:

  • 22.0 ms — Gutenberg: no syntax highlighting, no search index, no sass compilation.
  • 59.0 ms — Hugo: syntax highlighting, no search index, no sass compilation.
  • 68.2 ms — Gutenberg: syntax highlighting, no search index, no sass compilation.
  • 104.5 ms — Gutenberg: no syntax highlighting, search index, no sass compilation.
  • 152.0 ms — Gutenberg: syntax highlighting, search index, no sass compilation.

(Note: I don't currently use sass for my site, so I didn't test the speed of the sass compilation. I did turn it on a few times to make sure that checking for sass files did not take any measurable time; as expected, that option had no impact on speed).

I am a little confused by what you meant when you asked "Is that the full build or only the rebuild time". I would have thought that it was the rebuild time: it was the time I got from running gutenberg build. But I also ran rm -rf public; gutenberg build, and got essentially the same time. (Well, technically, I had hyperfine run rm -rf as a "prepare" command, and got exactly the same time. So it looks a bit like gutenberg build is triggering a full build. Is there a way to just do a rebuild? Or is it the case that, with a small site, there literally isn't a measurable difference between the two types of build?

Thanks again for your reply and your work on this project. I'm definitely planning to switch!

@Keats

This comment has been minimized.

Copy link
Collaborator

Keats commented Jul 1, 2018

Sorry for the confusion, gutenberg build will rebuild the whole thing. I was only wondering if you were using gutenberg serve and editing a file - where it does partial reload like Hugo.

So Hugo & Gutenberg are at the same speed roughly despite the syntax highlighting being much more powerful in Gutenberg :o Pretty nice to know.

The search index is actually not built in parallel currently but I'm not sure it would be a significant speed increase, I'll have to add benchmarks and try it.

@codesections

This comment has been minimized.

Copy link
Contributor

codesections commented Jul 1, 2018

Thanks, that makes sense. Just curious, what "more powerful" features does the Gutenberg syntax highlighting have compared to the Chroma highlighting in Hugo?

@Keats

This comment has been minimized.

Copy link
Collaborator

Keats commented Jul 1, 2018

Chroma is basically Pygments in Go so it just highlights keywords.
Syntect uses the Sublime Text highlighting syntaxes so you get context-aware highlighting and it is overall much more refined.
As an example, compare the python Pygments syntax (https://github.com/alecthomas/chroma/blob/master/lexers/p/python3.go) with the sublime one (https://github.com/sublimehq/Packages/blob/master/Python/Python.sublime-syntax). For more visual comparison, you can download sublime and look at some code VS running it in http://pygments.org

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