summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-11-15 22:49:48 -0800
committerStan Hu <stanhu@gmail.com>2018-11-16 00:23:36 -0800
commit198f2a0b6149a2e7c069ad3aaad6ced9f5bb3ea1 (patch)
treebf41d60dccb32bbb689bb853655535a691963981
parent6494467a191f119af31ce3e8d3f32885c1244bdc (diff)
downloadgitlab-ce-198f2a0b6149a2e7c069ad3aaad6ced9f5bb3ea1.tar.gz
Use Nokogiri as the ActiveSupport XML backendsh-use-nokogiri-xml-backend
This significantly improves performance and reduces memory consumption when parsing XML files. On a test with 124 JUnit files from a CE build, there was about a 4x reduction in processing time. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/54068
-rw-r--r--changelogs/unreleased/sh-use-nokogiri-xml-backend.yml5
-rw-r--r--config/application.rb3
-rw-r--r--lib/gitlab/ci/parsers/test/junit.rb2
-rw-r--r--spec/fast_spec_helper.rb1
4 files changed, 10 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-use-nokogiri-xml-backend.yml b/changelogs/unreleased/sh-use-nokogiri-xml-backend.yml
new file mode 100644
index 00000000000..6a82e32c416
--- /dev/null
+++ b/changelogs/unreleased/sh-use-nokogiri-xml-backend.yml
@@ -0,0 +1,5 @@
+---
+title: Use Nokogiri as the ActiveSupport XML backend
+merge_request: 23136
+author:
+type: performance
diff --git a/config/application.rb b/config/application.rb
index 1b084e91cfb..921baa5d617 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -158,6 +158,9 @@ module Gitlab
config.action_view.sanitized_allowed_protocols = %w(smb)
+ # Nokogiri is significantly faster and uses less memory than REXML
+ ActiveSupport::XmlMini.backend = 'Nokogiri'
+
# This middleware needs to precede ActiveRecord::QueryCache and other middlewares that
# connect to the database.
config.middleware.insert_after Rails::Rack::Logger, ::Gitlab::Middleware::BasicHealthCheck
diff --git a/lib/gitlab/ci/parsers/test/junit.rb b/lib/gitlab/ci/parsers/test/junit.rb
index ed5a79d9b9b..2791730fd26 100644
--- a/lib/gitlab/ci/parsers/test/junit.rb
+++ b/lib/gitlab/ci/parsers/test/junit.rb
@@ -14,7 +14,7 @@ module Gitlab
test_case = create_test_case(test_case)
test_suite.add_test_case(test_case)
end
- rescue REXML::ParseException
+ rescue Nokogiri::XML::SyntaxError
raise JunitParserError, "XML parsing failed"
rescue
raise JunitParserError, "JUnit parsing failed"
diff --git a/spec/fast_spec_helper.rb b/spec/fast_spec_helper.rb
index fe475e1f7a0..0b5ab16ad71 100644
--- a/spec/fast_spec_helper.rb
+++ b/spec/fast_spec_helper.rb
@@ -9,3 +9,4 @@ require 'active_support/all'
ActiveSupport::Dependencies.autoload_paths << 'lib'
ActiveSupport::Dependencies.autoload_paths << 'ee/lib'
+ActiveSupport::XmlMini.backend = 'Nokogiri'