From c153b4a1e91f31965d120a80184353f1d9db0a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Joubert?= Date: Thu, 22 Oct 2026 19:13:30 +0300 Subject: [PATCH] Autoload RSS::Maker require "rss" loaded the feed generators along with the parsers. Apps that only parse feeds now skip rss/maker: about 97k allocated objects, 24k retained objects and 5 MB RSS less per process. --- lib/rss.rb | 3 +-- test/test-autoload.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/test-autoload.rb diff --git a/lib/rss.rb b/lib/rss.rb index 7c88448..a246f2a 100644 --- a/lib/rss.rb +++ b/lib/rss.rb @@ -70,6 +70,7 @@ # http://www.cozmixng.org/~rwiki/?cmd=view;name=RSS+Parser%3A%3ATutorial.en module RSS + autoload :Maker, "rss/maker" end require "rss/version" @@ -85,5 +86,3 @@ module RSS require "rss/syndication" require "rss/taxonomy" require "rss/trackback" - -require "rss/maker" diff --git a/test/test-autoload.rb b/test/test-autoload.rb new file mode 100644 index 0000000..540abc8 --- /dev/null +++ b/test/test-autoload.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: false +require_relative "rss-testcase" + +module RSS + class TestAutoload < TestCase + def test_maker_loaded_on_first_use + lib_dir = File.expand_path("../lib", __dir__) + script = <<~SCRIPT + require "rss" + maker_loaded = -> { $LOADED_FEATURES.any? { |path| path.end_with?("/rss/maker.rb") } } + print maker_loaded.call, " " + RSS::Maker + print maker_loaded.call + SCRIPT + output = IO.popen([RbConfig.ruby, "-I", lib_dir, "-e", script], &:read) + assert_equal("false true", output) + end + end +end