BigW Consortium Gitlab
By using Rouge::Lexer.find instead of find_fancy() and memoizing the HTML formatter we can speed up the highlighting process by between 1.7 and 1.8 times (at least when measured using synthetic benchmarks). To measure this I used the following benchmark: require 'benchmark/ips' input = '' Dir['./app/controllers/**/*.rb'].each do |controller| input << <<-EOF <pre><code class="ruby">#{File.read(controller).strip}</code></pre> EOF end document = Nokogiri::HTML.fragment(input) filter = Banzai::Filter::SyntaxHighlightFilter.new(document) puts "Input size: #{(input.bytesize.to_f / 1024).round(2)} KB" Benchmark.ips do |bench| bench.report 'call' do filter.call end end This benchmark produces 250 KB of input. Before these changes the timing output would be as follows: Calculating ------------------------------------- call 1.000 i/100ms ------------------------------------------------- call 22.439 (±35.7%) i/s - 93.000 After these changes the output instead is as follows: Calculating ------------------------------------- call 1.000 i/100ms ------------------------------------------------- call 41.283 (±38.8%) i/s - 148.000 Note that due to the fairly high standard deviation and this being a synthetic benchmark it's entirely possible the real-world improvements are smaller.
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
wiki_link_filter | Loading commit data... | |
abstract_reference_filter.rb | Loading commit data... | |
autolink_filter.rb | Loading commit data... | |
blockquote_fence_filter.rb | Loading commit data... | |
commit_range_reference_filter.rb | Loading commit data... | |
commit_reference_filter.rb | Loading commit data... | |
emoji_filter.rb | Loading commit data... | |
external_issue_reference_filter.rb | Loading commit data... | |
external_link_filter.rb | Loading commit data... | |
gollum_tags_filter.rb | Loading commit data... | |
image_link_filter.rb | Loading commit data... | |
inline_diff_filter.rb | Loading commit data... | |
issue_reference_filter.rb | Loading commit data... | |
label_reference_filter.rb | Loading commit data... | |
markdown_filter.rb | Loading commit data... | |
merge_request_reference_filter.rb | Loading commit data... | |
milestone_reference_filter.rb | Loading commit data... | |
redactor_filter.rb | Loading commit data... | |
reference_filter.rb | Loading commit data... | |
relative_link_filter.rb | Loading commit data... | |
sanitization_filter.rb | Loading commit data... | |
snippet_reference_filter.rb | Loading commit data... | |
syntax_highlight_filter.rb | Loading commit data... | |
table_of_contents_filter.rb | Loading commit data... | |
task_list_filter.rb | Loading commit data... | |
upload_link_filter.rb | Loading commit data... | |
user_reference_filter.rb | Loading commit data... | |
video_link_filter.rb | Loading commit data... | |
wiki_link_filter.rb | Loading commit data... | |
yaml_front_matter_filter.rb | Loading commit data... |