Use Nokogiri as the ActiveSupport 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
This commit is contained in:
Stan Hu 2018-11-15 22:49:48 -08:00
parent 6494467a19
commit 198f2a0b61
4 changed files with 10 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
title: Use Nokogiri as the ActiveSupport XML backend
merge_request: 23136
author:
type: performance

View file

@ -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

View file

@ -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"

View file

@ -9,3 +9,4 @@ require 'active_support/all'
ActiveSupport::Dependencies.autoload_paths << 'lib'
ActiveSupport::Dependencies.autoload_paths << 'ee/lib'
ActiveSupport::XmlMini.backend = 'Nokogiri'