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 0000000000000000000000000000000000000000..6a82e32c416373bfd3a9cb0601115edb365e4170
--- /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 1b084e91cfbd61f01ea8fdb45685a6a4ca11b922..921baa5d617a4cbaf44f55901a8ab3b9cb54deb7 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -158,6 +158,9 @@ class Application < Rails::Application
 
     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 ed5a79d9b9b066cb580cfe75bdc9504a654074d5..2791730fd26cb203b57a14e28c9e756f82ba455c 100644
--- a/lib/gitlab/ci/parsers/test/junit.rb
+++ b/lib/gitlab/ci/parsers/test/junit.rb
@@ -14,7 +14,7 @@ def parse!(xml_data, test_suite)
               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 fe475e1f7a0abbf03ac8f8af2afcd8e8bc260d07..0b5ab16ad71c35faaa29b0ef1e4b2d01b2ada9be 100644
--- a/spec/fast_spec_helper.rb
+++ b/spec/fast_spec_helper.rb
@@ -9,3 +9,4 @@
 
 ActiveSupport::Dependencies.autoload_paths << 'lib'
 ActiveSupport::Dependencies.autoload_paths << 'ee/lib'
+ActiveSupport::XmlMini.backend = 'Nokogiri'