diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-13 00:09:10 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-13 00:09:10 +0000 |
commit | 71d4234fa1047943240e129b73ca41e751711520 (patch) | |
tree | 648cb8c02eccd3c8e00be115d77422f23beabb66 /spec/benchmarks | |
parent | eef0c69d45082b370f1e41e50f12488a216944f2 (diff) | |
download | gitlab-ce-71d4234fa1047943240e129b73ca41e751711520.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/benchmarks')
-rw-r--r-- | spec/benchmarks/banzai_benchmark.rb | 182 |
1 files changed, 96 insertions, 86 deletions
diff --git a/spec/benchmarks/banzai_benchmark.rb b/spec/benchmarks/banzai_benchmark.rb index e489237a2f2..a87414ba512 100644 --- a/spec/benchmarks/banzai_benchmark.rb +++ b/spec/benchmarks/banzai_benchmark.rb @@ -1,114 +1,124 @@ # frozen_string_literal: true -if ENV.key?('BENCHMARK') - require 'spec_helper' - require 'erb' - require 'benchmark/ips' - - # This benchmarks some of the Banzai pipelines and filters. - # They are not definitive, but can be used by a developer to - # get a rough idea how the changing or addition of a new filter - # will effect performance. - # - # Run by: - # BENCHMARK=1 rspec spec/benchmarks/banzai_benchmark.rb - # or - # rake benchmark:banzai - # - RSpec.describe 'GitLab Markdown Benchmark', :aggregate_failures do - include MarkupHelper - - let_it_be(:feature) { MarkdownFeature.new } - let_it_be(:project) { feature.project } - let_it_be(:group) { feature.group } - let_it_be(:wiki) { feature.wiki } - let_it_be(:wiki_page) { feature.wiki_page } - let_it_be(:markdown_text) { feature.raw_markdown } - - let!(:render_context) { Banzai::RenderContext.new(project, current_user) } - - before do - stub_application_setting(asset_proxy_enabled: true) - stub_application_setting(asset_proxy_secret_key: 'shared-secret') - stub_application_setting(asset_proxy_url: 'https://assets.example.com') - stub_application_setting(asset_proxy_whitelist: %w(gitlab.com *.mydomain.com)) - - Banzai::Filter::AssetProxyFilter.initialize_settings - end +return unless ENV.key?('BENCHMARK') + +require 'spec_helper' +require 'erb' +require 'benchmark/ips' + +# This benchmarks some of the Banzai pipelines and filters. +# They are not definitive, but can be used by a developer to +# get a rough idea how the changing or addition of a new filter +# will effect performance. +# +# Run by: +# BENCHMARK=1 rspec spec/benchmarks/banzai_benchmark.rb +# or +# rake benchmark:banzai +# +# rubocop: disable RSpec/TopLevelDescribePath +RSpec.describe 'GitLab Markdown Benchmark', :aggregate_failures do + include MarkupHelper + + let_it_be(:feature) { MarkdownFeature.new } + let_it_be(:project) { feature.project } + let_it_be(:group) { feature.group } + let_it_be(:wiki) { feature.wiki } + let_it_be(:wiki_page) { feature.wiki_page } + let_it_be(:markdown_text) { feature.raw_markdown } + let_it_be(:grafana_integration) { create(:grafana_integration, project: project) } + let_it_be(:default_context) do + { + project: project, + current_user: current_user, + suggestions_filter_enabled: true + } + end - context 'pipelines' do - it 'benchmarks several pipelines' do - path = 'images/example.jpg' - gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path) - allow(wiki).to receive(:find_file).with(path).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file)) - allow(wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' } + let(:context) do + Banzai::Filter::AssetProxyFilter.transform_context(default_context) + end - puts "\n--> Benchmarking Full, Wiki, and Plain pipelines\n" + let!(:render_context) { Banzai::RenderContext.new(project, current_user) } - Benchmark.ips do |x| - x.config(time: 10, warmup: 2) + before do + stub_application_setting(asset_proxy_enabled: true) + stub_application_setting(asset_proxy_secret_key: 'shared-secret') + stub_application_setting(asset_proxy_url: 'https://assets.example.com') + stub_application_setting(asset_proxy_whitelist: %w(gitlab.com *.mydomain.com)) + stub_application_setting(plantuml_enabled: true, plantuml_url: 'http://localhost:8080') + stub_application_setting(kroki_enabled: true, kroki_url: 'http://localhost:8000') - x.report('Full pipeline') { markdown(markdown_text, { pipeline: :full }) } - x.report('Wiki pipeline') { markdown(markdown_text, { pipeline: :wiki, wiki: wiki, page_slug: wiki_page.slug }) } - x.report('Plain pipeline') { markdown(markdown_text, { pipeline: :plain_markdown }) } + Banzai::Filter::AssetProxyFilter.initialize_settings + end - x.compare! - end - end - end + context 'pipelines' do + it 'benchmarks several pipelines' do + path = 'images/example.jpg' + gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path) + allow(wiki).to receive(:find_file).with(path).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file)) + allow(wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' } - context 'filters' do - let(:context) do - tmp = { project: project, current_user: current_user, render_context: render_context } - Banzai::Filter::AssetProxyFilter.transform_context(tmp) - end + puts "\n--> Benchmarking Full, Wiki, and Plain pipelines\n" - it 'benchmarks all filters in the FullPipeline' do - benchmark_pipeline_filters(:full) - end + Benchmark.ips do |x| + x.config(time: 10, warmup: 2) + + x.report('Full pipeline') { Banzai::Pipeline::FullPipeline.call(markdown_text, context) } + x.report('Wiki pipeline') { Banzai::Pipeline::WikiPipeline.call(markdown_text, context.merge(wiki: wiki, page_slug: wiki_page.slug)) } + x.report('Plain pipeline') { Banzai::Pipeline::PlainMarkdownPipeline.call(markdown_text, context) } - it 'benchmarks all filters in the PlainMarkdownPipeline' do - benchmark_pipeline_filters(:plain_markdown) + x.compare! end end + end - # build up the source text for each filter - def build_filter_text(pipeline, initial_text) - filter_source = {} - input_text = initial_text + context 'filters' do + it 'benchmarks all filters in the FullPipeline' do + benchmark_pipeline_filters(:full) + end - pipeline.filters.each do |filter_klass| - filter_source[filter_klass] = input_text + it 'benchmarks all filters in the PlainMarkdownPipeline' do + benchmark_pipeline_filters(:plain_markdown) + end + end - output = filter_klass.call(input_text, context) - input_text = output - end + # build up the source text for each filter + def build_filter_text(pipeline, initial_text) + filter_source = {} + input_text = initial_text - filter_source + pipeline.filters.each do |filter_klass| + filter_source[filter_klass] = input_text + + output = filter_klass.call(input_text, context) + input_text = output end - def benchmark_pipeline_filters(pipeline_type) - pipeline = Banzai::Pipeline[pipeline_type] - filter_source = build_filter_text(pipeline, markdown_text) + filter_source + end - puts "\n--> Benchmarking #{pipeline.name.demodulize} filters\n" + def benchmark_pipeline_filters(pipeline_type) + pipeline = Banzai::Pipeline[pipeline_type] + filter_source = build_filter_text(pipeline, markdown_text) - Benchmark.ips do |x| - x.config(time: 10, warmup: 2) + puts "\n--> Benchmarking #{pipeline.name.demodulize} filters\n" - pipeline.filters.each do |filter_klass| - label = filter_klass.name.demodulize.delete_suffix('Filter').truncate(20) + Benchmark.ips do |x| + x.config(time: 10, warmup: 2) - x.report(label) { filter_klass.call(filter_source[filter_klass], context) } - end + pipeline.filters.each do |filter_klass| + label = filter_klass.name.demodulize.delete_suffix('Filter').truncate(20) - x.compare! + x.report(label) { filter_klass.call(filter_source[filter_klass], context) } end - end - # Fake a `current_user` helper - def current_user - feature.user + x.compare! end end + + # Fake a `current_user` helper + def current_user + feature.user + end end |