Possible build CI/CD performance improvement for handbook
Hi!
I did some analysis on the handbook build process and noticed that with a small regex change on middleman, was able to reduce the build time for the handbook locally on my machine by ~33%. Would be curious to know what effect if any it would have in your CI/CD pipeline!
From what I was able to deduce, the below loop was being executed ~33m times when building GitLab's handbook (store.resources size of ~3.3k and the function being ran ~10k times), so any minor improvement helped a lot. The concept in general could probably do with some more refactoring, but this was a decent start:
--- a/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb
+++ b/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb
@@ -26,9 +26,10 @@ def parent
end
test_expr = parts.join('\\/')
+ test_expr = %r{^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$}
# eponymous reverse-lookup
found = @store.resources.find do |candidate|
- candidate.path =~ %r{^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$}
+ candidate.path =~ test_expr
end
if found
I went ahead and submitted a pull request to middleman for this against their 4.x
branch, but in case you wanted to play around with it yourself first (not sure how much activity middleman gets these days), and/or patch it in to see if there's a more immediate improvement in your build jobs.