rails-minify 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: debbde5867be2f422c20756ebf3c08185983f80f1f94b1f9be9ffa5f29283989
4
- data.tar.gz: d42eca099bc0278d05c81a868ec03eccd844635799e0d826900680324fd56558
3
+ metadata.gz: 44f089252dbde289b9e5cfeb25c2613e91544e92a1235369ec7c4457992e477b
4
+ data.tar.gz: c768e54a78cd0ee553f8732f019dc4eab9fff3c5c72d4ef9d30d23abc68b2994
5
5
  SHA512:
6
- metadata.gz: 835c2eb9c3a2b1210977d40eaaafc28fe399d7755c3681d6c0adaef25b3063c6f43e699f4924015d404deb083ae9e26324e7f524bd51687b937866fc3d10c08b
7
- data.tar.gz: 1a04e068acaaa2991c5e8c8f0ea4ec51145acde7d7285ef2c05d422b05754b733f776e269398449b8b6675f8b647aa2d95df9eb077cc55084851d5844045eae3
6
+ metadata.gz: da6b92c40d4f1fada0154fb362cd52c8a56e458b67e5d959e20084bb4e37f25a8be93d7d86bc065d6a71ac09dc4763c79fbada65a4f7a73c281c8b9fef511d1b
7
+ data.tar.gz: 8cca5d4c9850e66798cdb80127907dbfc64cdf5643d1064a7ce01be6bfdd8f46b79bbf63e9e8c80775dd6c3453d9877537bd6951707cb434378049fdb0a92227
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.3 (2026-10-18)
4
+
5
+ - `config.rails_minify.zjit = true` turns ZJIT on after boot, as `config.yjit` does for YJIT, instead of `RUBY_ZJIT_ENABLE=1` compiling boot-only code too. Japan Voyage, per process: 24% fewer compiled methods, 18 MB less JIT memory, about 25 MB less RSS, the same speed.
6
+
7
+ ## 0.1.2 (2026-10-18)
8
+
9
+ - `minify:check` also fails on callback chains longer than `callback_limit` (default 5, `ApplicationController`'s callbacks excluded) and on model callbacks that save their own record again; `callback_limit_mode` and `callback_loops` set either to `:warn`. Works without the rest of rails-minify turned on; the manifest check runs only when there is a manifest.
10
+ - Requires activesupport-minimizer 0.1.1.
11
+
3
12
  ## 0.1.1 (2026-10-18)
4
13
 
5
14
  - `:omniauth` isn't installed when OmniAuth already skips requests that can't be the strategy's (a public `Strategy#passthrough?`, as in the version proposed upstream); its own helper no longer shares that name.
data/README.md CHANGED
@@ -14,6 +14,19 @@ config.rails_minify.enabled = true
14
14
  (`config.ar_minimizer.enums = false`, `config.rails_minify.patches = [:omniauth]`).
15
15
  Ruby 3.4+, Rails 8.0, 8.1 and main.
16
16
 
17
+ Turn it on in tests too, so a call to a method strict mode removed fails in CI
18
+ rather than in production. In development, strict mode alone is enough: the
19
+ same errors show up while you work, and the compiling parts, which don't
20
+ follow code reloads, stay off.
21
+
22
+ ```ruby
23
+ # config/environments/test.rb
24
+ config.rails_minify.enabled = true
25
+
26
+ # config/environments/development.rb
27
+ config.ar_minimizer.slim = true # strict mode, without the rest
28
+ ```
29
+
17
30
  ## Strict by default
18
31
 
19
32
  Active Record defines, for every column, a reader, a writer and 19 more
@@ -71,6 +84,22 @@ For parts of Rails and common gems that redo work on every request.
71
84
  installed when OmniAuth already does this itself (it then has a public
72
85
  `Strategy#passthrough?`, as in the version proposed upstream).
73
86
 
87
+ ## ZJIT after boot
88
+
89
+ ```ruby
90
+ config.rails_minify.zjit = true # instead of RUBY_ZJIT_ENABLE=1 / --zjit
91
+ ```
92
+
93
+ `RUBY_ZJIT_ENABLE=1` turns ZJIT on before anything loads, so it also compiles
94
+ what runs only while booting: RubyGems, requiring and eager loading, and the
95
+ minimizers' own compiling. Rails turns YJIT on after boot (`config.yjit`) for
96
+ this reason, but has no such setting for ZJIT; this is that one. It works on
97
+ its own, without the rest of rails-minify.
98
+
99
+ On Japan Voyage, per process after the same 132 pages: 12,612 → 9,557
100
+ compiled methods, JIT code 45.9 → 35.3 MB, ZJIT memory 82.9 → 64.6 MB,
101
+ RSS about 25 MB less, the same CPU time per page.
102
+
74
103
  ## Numbers
75
104
 
76
105
  Japan Voyage, 132 production pages, with everything on (strict mode after
@@ -81,7 +110,26 @@ loaded for wall-clock times to mean much.
81
110
  ## Checks
82
111
 
83
112
  * `bin/rails minify:census`: how much of the app runs compiled, and why the rest doesn't.
84
- * `bin/rails minify:check`: callbacks naming methods that don't exist (for CI).
113
+ * `bin/rails minify:check` (for CI; works whether or not the rest of
114
+ rails-minify is on) fails on:
115
+ * callbacks naming methods that don't exist;
116
+ * callback chains with more than `callback_limit` (default 5) of the app's
117
+ own callbacks (Rails' and gems' don't count; controllers per action).
118
+ Callbacks inherited from `callback_limit_exclude` (default
119
+ `["ApplicationController"]`: time zone, locale, current user, the
120
+ per-request basics) don't count either. A base class over the limit is
121
+ reported once, with the classes that inherit it;
122
+ * model callbacks that call `save`, `update`, `touch`, ... on the record
123
+ they run for, which runs the chain again;
124
+ * an out-of-date manifest.
125
+
126
+ ```ruby
127
+ config.rails_minify.callback_limit = 8
128
+ config.rails_minify.callback_limit_exclude = ["ApplicationController", "Admin::BaseController"] # [] counts everything
129
+ config.rails_minify.callback_limit_mode = :warn # report, don't fail
130
+ config.rails_minify.callback_loops = :warn
131
+ config.rails_minify.allow_callback_loops = ["Trip#recalculate"] # guarded on purpose
132
+ ```
85
133
 
86
134
  ## Things found that are app config, not patches
87
135
 
@@ -42,6 +42,18 @@ module RailsMinify
42
42
  end
43
43
  end
44
44
 
45
+ # ZJIT from after boot, as Rails does for YJIT (config.yjit): the code
46
+ # that only runs while booting (requiring, eager loading, the minimizers'
47
+ # compiling) isn't compiled. Japan Voyage, per process: 24% fewer
48
+ # compiled methods, 18 MB less JIT memory, the same speed.
49
+ initializer "rails_minify.zjit" do |app|
50
+ config.after_initialize do
51
+ next unless app.config.rails_minify.zjit && defined?(RubyVM::ZJIT.enable) && !RubyVM::ZJIT.enabled?
52
+
53
+ RubyVM::ZJIT.enable
54
+ end
55
+ end
56
+
45
57
  rake_tasks do
46
58
  namespace :minify do
47
59
  prepare = lambda do
@@ -69,15 +81,39 @@ module RailsMinify
69
81
  end
70
82
  end
71
83
 
72
- desc "Fail on what would break at runtime or compile stale: missing callback targets, an out-of-date manifest"
84
+ desc "Fail on callback problems (missing targets, chains longer than callback_limit, " \
85
+ "callbacks that save their own record) and an out-of-date manifest"
73
86
  task check: :environment do
74
87
  app = prepare.call
75
- problems = AsMinimizer::Check.callback_targets(routed: AsMinimizer::Check.routed_actions(app.routes))
76
- missing = problems.select { it.status == :missing }
77
- missing.each { puts " #{it}" }
78
- manifest = ArMinimizer::Census.manifest_state(app.root, ArMinimizer::Index.from_models)
79
- puts "callback targets: #{missing.size} missing; manifest: #{manifest}"
80
- abort if missing.any? || manifest.start_with?("out of date")
88
+ options = app.config.rails_minify
89
+ routed = AsMinimizer::Check.routed_actions(app.routes)
90
+ failed = false
91
+ report = lambda do |title, items, mode|
92
+ next puts("#{title}: none") if items.empty?
93
+
94
+ puts "#{title}: #{items.size}#{" (warning)" if mode == :warn}"
95
+ items.each { puts " #{it}" }
96
+ failed ||= mode != :warn
97
+ end
98
+
99
+ missing = AsMinimizer::Check.callback_targets(routed: routed).select { it.status == :missing }
100
+ report.("callback targets naming no method", missing, :fail)
101
+
102
+ limit = options.callback_limit || 5
103
+ report.("callback chains with more than #{limit} of the app's callbacks",
104
+ AsMinimizer::Check.long_chains(limit: limit, root: app.root.to_s, routed: routed,
105
+ exclude: options.callback_limit_exclude.nil? ? ["ApplicationController"] : Array(options.callback_limit_exclude)),
106
+ (options.callback_limit_mode || :fail).to_sym)
107
+
108
+ report.("callbacks saving their own record",
109
+ AsMinimizer::Check.callback_loops(root: app.root.to_s, allow: Array(options.allow_callback_loops)), (options.callback_loops || :fail).to_sym)
110
+
111
+ if defined?(ArMinimizer::Census) && app.root.join("config/ar_minimizer.json").exist?
112
+ manifest = ArMinimizer::Census.manifest_state(app.root, ArMinimizer::Index.from_models)
113
+ puts "manifest: #{manifest}"
114
+ failed ||= manifest.start_with?("out of date")
115
+ end
116
+ abort if failed
81
117
  end
82
118
  end
83
119
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsMinify
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-minify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampo Kuokkanen
@@ -44,6 +44,9 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0.1'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.1.1
47
50
  type: :runtime
48
51
  prerelease: false
49
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -51,6 +54,9 @@ dependencies:
51
54
  - - "~>"
52
55
  - !ruby/object:Gem::Version
53
56
  version: '0.1'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.1.1
54
60
  description: Turns on activerecord-, activesupport- and actionpack-minimizer, and
55
61
  patches parts of Rails and common gems that redo work on every request (Action Text
56
62
  plain text, Request#host, OmniAuth strategies).