rails-minify 0.3.0 → 0.4.0

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: c682f7b5f509613697d35d78e163167b825525a03aae99fecb6ab430550f2429
4
- data.tar.gz: dd258711680a2472583815a96af871f418d8fac5cf06f323c2dc7f102908e962
3
+ metadata.gz: 0723afe45486f260e81aee94e48c979e29a863991b960203a55397c932871792
4
+ data.tar.gz: 3bfa12203cc106068fbb22c6d844eff0ed68f564886a74be94953f1e817bebe1
5
5
  SHA512:
6
- metadata.gz: 29a12e198162b3bd148f39d2f7be79e69aa32d471164120d1055a8c2960a97f7afee2a1dd2728b30dfe6e8f2d8f22b528a854420600f3ae1d3e325077265ce60
7
- data.tar.gz: c2031ba5b96903be93f11d324afe736b18c476f420467e1a48503b4ac397ee24540812e7173819aa1ff6fd97e5025c7ac865616f7ad15d0db0498de29f2144eb
6
+ metadata.gz: e000f5a93f901772654e1c4219ea36a171970de119b6f2ada233a614bf198deb66c6e79334016dba7a7be17338d4532dbce711ad2d4538e1f22172e129327767
7
+ data.tar.gz: '09466303155a247edecff33e03b9b1fc5569abce784b9e95b3f471990b34a56c6ed1e6bd8f5affc8b5bb8030528398dc1e00a97c187932932f3f3092c2545a7e'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0 (2026-11-05)
4
+
5
+ - Requires activerecord-minimizer 0.3.
6
+ - Removed `config.rails_minify.enabled` and `config.rails_minify.zjit`. ZJIT after boot is in Rails main as `config.zjit = true` (rails/rails#59183); with enums gone too (activerecord-minimizer removed them: no measured gain in production, and they no longer worked on Rails main), `enabled` only turned on strict mode, so set `config.ar_minimizer.slim = true` instead. Setting either removed option prints a warning saying what to set.
7
+ - `minify:doctor` suggests Rails' `config.zjit = true` for a ZJIT turned on before boot.
8
+
3
9
  ## 0.3.0 (2026-11-04)
4
10
 
5
11
  - `config.rails_minify.sql_profile = 0.01` samples requests and logs each distinct query and call site with its calls, time and rows, plus the request's SQL and instantiation time; `bin/rails minify:sql:report LOG=...` ranks actions and queries by total time, and with `EXPLAIN=1` adds SQLite query plans and flags full table scans and sorts without an index.
data/README.md CHANGED
@@ -1,37 +1,20 @@
1
1
  # rails-minify
2
2
 
3
- Fewer generated Active Record methods, ZJIT turned on after boot, and checks
4
- for callback problems.
3
+ Fewer generated Active Record methods, production profiling and
4
+ configuration checks, and checks for callback problems.
5
5
 
6
6
  ```ruby
7
7
  # Gemfile
8
8
  gem "rails-minify"
9
9
 
10
- # config/environments/production.rb
11
- config.rails_minify.enabled = true
10
+ # config/application.rb
11
+ config.ar_minimizer.slim = true # strict mode
12
12
  ```
13
13
 
14
- `enabled` turns on what held up in production on a real app:
15
-
16
- * strict mode (`config.ar_minimizer.slim`): only readers and writers per column;
17
- * enum predicates and bang methods as plain methods (`config.ar_minimizer.enums`);
18
- * ZJIT after boot (`config.rails_minify.zjit`), in production on Ruby 4.1+.
19
-
20
- Each can still be set on its own (`config.ar_minimizer.enums = false`).
21
- Everything else is [experimental](#experimental) and off unless you set it.
22
- Ruby 3.4+, Rails 8.0, 8.1 and main.
23
-
24
- Turn it on in tests too, so a call to a method strict mode removed fails in CI
25
- rather than in production. In development, strict mode alone is enough: the
26
- same errors show up while you work.
27
-
28
- ```ruby
29
- # config/environments/test.rb
30
- config.rails_minify.enabled = true
31
-
32
- # config/environments/development.rb
33
- config.ar_minimizer.slim = true # strict mode, without the rest
34
- ```
14
+ Set strict mode in every environment, so a call to a method it removed fails
15
+ while you work and in CI rather than in production. Everything else is
16
+ [experimental](#experimental) and off unless you set it. Ruby 3.4+, Rails 8.0,
17
+ 8.1 and main.
35
18
 
36
19
  ## Strict mode
37
20
 
@@ -54,20 +37,16 @@ instead, generated the first time each is called.
54
37
 
55
38
  ## ZJIT after boot
56
39
 
57
- ```ruby
58
- config.rails_minify.zjit = true # instead of RUBY_ZJIT_ENABLE=1 / --zjit
59
- ```
60
-
61
- `enabled` sets it in production on Ruby 4.1 and later; on 4.0, ZJIT isn't
62
- meant for production yet, so set it yourself if you want it there. ZJIT
63
- options still go in `RUBYOPT`, after `--zjit-disable` so they don't turn it
64
- on at startup: `RUBYOPT="--zjit-disable --zjit-call-threshold=2"`.
65
-
66
- `RUBY_ZJIT_ENABLE=1` turns ZJIT on before anything loads, so it also compiles
67
- what runs only while booting: RubyGems, requiring and eager loading, and the
68
- minimizers' own compiling. Rails turns YJIT on after boot (`config.yjit`) for
69
- this reason, but has no such setting for ZJIT; this is that one. It works on
70
- its own, without the rest of rails-minify.
40
+ Rails main has this now: `config.zjit = true`
41
+ ([rails/rails#59183](https://github.com/rails/rails/pull/59183)), the ZJIT
42
+ counterpart of `config.yjit`, so rails-minify no longer has its own setting.
43
+ Use it instead of `RUBY_ZJIT_ENABLE=1` or `--zjit`, which turn ZJIT on before
44
+ anything loads, so it also compiles what runs only while booting: RubyGems,
45
+ requiring and eager loading. ZJIT options still go in `RUBYOPT`, after
46
+ `--zjit-disable` so they don't turn it on at startup:
47
+ `RUBYOPT="--zjit-disable --zjit-call-threshold=2"`. Use Ruby 4.1 or later;
48
+ 4.0's ZJIT isn't meant for production. `minify:doctor` reports a JIT turned on
49
+ before boot.
71
50
 
72
51
  On Japan Voyage, per process after the same 132 pages: 12,612 → 9,557
73
52
  compiled methods, JIT code 45.9 → 35.3 MB, ZJIT memory 82.9 → 64.6 MB,
@@ -208,8 +187,8 @@ without it, under the same traffic (about 5,000 requests per half):
208
187
 
209
188
  | part | in production | in 0.2.0 |
210
189
  |---|---|---|
211
- | ZJIT after boot | HTML p50/p90/p99 75/131/231 → 70/126/208 ms, ~25 MB less per worker (an hour before against an hour after) | on with `enabled` (production, Ruby 4.1+) |
212
- | enums | the same medians; that hour's lower mean and p99 came from a few slow requests, as it changes no allocations on these pages | on with `enabled`: harmless, no measured gain |
190
+ | ZJIT after boot | HTML p50/p90/p99 75/131/231 → 70/126/208 ms, ~25 MB less per worker (an hour before against an hour after) | on with `enabled` (production, Ruby 4.1+); now Rails' `config.zjit` |
191
+ | enums | the same medians; that hour's lower mean and p99 came from a few slow requests, as it changes no allocations on these pages | on with `enabled`; removed since (no measured gain, and it broke on Rails main) |
213
192
  | strict | the same latency and memory; no calls to a removed method | on with `enabled`, so production runs what the tests run |
214
193
  | small records | no difference (tens of records per request) | experimental |
215
194
  | route helpers | no difference in view time | experimental |
@@ -219,8 +198,8 @@ without it, under the same traffic (about 5,000 requests per half):
219
198
  | callbacks | no faster, ~20 MB more per worker | experimental |
220
199
  | patches | no difference (view time 25.3 vs 26.8 ms) | experimental |
221
200
 
222
- ZJIT after boot is the one part with a clear effect. What `enabled` turns on
223
- is what Japan Voyage runs.
201
+ ZJIT after boot is the one part with a clear effect, and it is in Rails now.
202
+ Japan Voyage runs strict mode and Rails' `config.zjit`.
224
203
 
225
204
  What the benchmarks speed up is per call: a method call, a Hash, a helper.
226
205
  A page there spends ~30 ms in Active Record and ~30 ms in views, and those
@@ -75,7 +75,7 @@ module RailsMinify
75
75
 
76
76
  Finding.new(:jit_before_boot, "JIT turned on before boot: #{found.join(", ")}", WHY_BOOT,
77
77
  "drop it and turn the JIT on after boot: config.yjit = true for YJIT, " \
78
- "config.rails_minify.zjit = true for ZJIT.")
78
+ "config.zjit = true for ZJIT (Rails main).")
79
79
  end
80
80
 
81
81
  def jit_options
@@ -8,7 +8,7 @@ module RailsMinify
8
8
  # minimizers' options.
9
9
  config.before_initialize do |app|
10
10
  Railtie.apply_ab(app.config)
11
- Railtie.apply_enabled(app.config)
11
+ Railtie.warn_removed(app.config)
12
12
  end
13
13
 
14
14
  # In an A/B run (rails-minify-ab), group B gets config.rails_minify.ab
@@ -23,20 +23,16 @@ module RailsMinify
23
23
  config.log_tags = [*tags, AB.log_tag(group)]
24
24
  end
25
25
 
26
- # `enabled` turns on what made no page slower in production and is worth
27
- # having for its own sake: strict mode (fewer generated methods, production
28
- # runs what the tests run), enums and ZJIT after boot. Everything else stays
29
- # off unless set on its own. ZJIT, like Rails' config.yjit default, not in
30
- # development and test, and only from Ruby 4.1: 4.0's ZJIT isn't meant for
31
- # production yet.
32
- def self.apply_enabled(config, env: Rails.env, ruby: RUBY_VERSION)
33
- options = config.rails_minify
34
- return unless options.enabled
35
-
36
- ar = config.ar_minimizer
37
- ar.slim = true if ar.slim.nil?
38
- ar.enums = true if ar.enums.nil?
39
- options.zjit = !env.local? && Gem::Version.new(ruby) >= Gem::Version.new("4.1") if options.zjit.nil?
26
+ REMOVED = {
27
+ enabled: "set config.ar_minimizer.slim = true for strict mode, and Rails' config.zjit = true for ZJIT",
28
+ zjit: "use Rails' config.zjit = true (Rails main), which turns ZJIT on after boot the same way",
29
+ }.freeze
30
+
31
+ # Options earlier versions read; setting one now would quietly do nothing.
32
+ def self.warn_removed(config, out: $stderr)
33
+ REMOVED.each do |name, instead|
34
+ out.puts "rails-minify: config.rails_minify.#{name} was removed; #{instead}." unless config.rails_minify[name].nil?
35
+ end
40
36
  end
41
37
 
42
38
  PATCHES = {
@@ -72,18 +68,6 @@ module RailsMinify
72
68
  SqlProfile.install!(rate: rate) if rate
73
69
  end
74
70
 
75
- # ZJIT from after boot, as Rails does for YJIT (config.yjit): the code
76
- # that only runs while booting (requiring, eager loading, the minimizers'
77
- # compiling) isn't compiled. Japan Voyage, per process: 24% fewer
78
- # compiled methods, 18 MB less JIT memory, the same speed.
79
- initializer "rails_minify.zjit" do |app|
80
- config.after_initialize do
81
- next unless app.config.rails_minify.zjit && defined?(RubyVM::ZJIT.enable) && !RubyVM::ZJIT.enabled?
82
-
83
- RubyVM::ZJIT.enable
84
- end
85
- end
86
-
87
71
  rake_tasks do
88
72
  namespace :minify do
89
73
  prepare = lambda do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsMinify
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/rails_minify.rb CHANGED
@@ -9,15 +9,11 @@ rescue LoadError => e
9
9
  raise unless e.path == "ap_minimizer"
10
10
  end
11
11
 
12
- # One switch:
12
+ # Strict mode, in every environment, so a call to a removed method fails in CI:
13
13
  #
14
- # # config/environments/production.rb
15
- # config.rails_minify.enabled = true
14
+ # config.ar_minimizer.slim = true # only readers and writers per column
16
15
  #
17
- # turns on, unless set otherwise on their own:
18
- # config.ar_minimizer.slim strict mode: only readers and writers per column
19
- # config.ar_minimizer.enums enum predicates/bang methods as plain methods
20
- # config.rails_minify.zjit ZJIT after boot
16
+ # ZJIT after boot is Rails' own config.zjit (Rails main).
21
17
  #
22
18
  # Experimental, each off unless set: the other minimizer options
23
19
  # (ar_minimizer.views, .load_time, .small_records, as_minimizer.unroll_callbacks,
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampo Kuokkanen
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.2'
18
+ version: '0.3'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0.2'
25
+ version: '0.3'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport-minimizer
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -37,10 +37,10 @@ dependencies:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0.2'
40
- description: 'One switch for what held up in production: Active Record strict mode
41
- (only readers and writers per column), enum methods without closures and ZJIT turned
42
- on after boot. minify:check finds callback problems. Experimental: patches for parts
43
- of Rails and common gems that redo work on every request, and the other minimizer
40
+ description: 'Active Record strict mode (only readers and writers per column), minify:check
41
+ for callback problems, minify:doctor for production configuration that costs speed
42
+ or memory, and SQL profiling from production traffic. Experimental: patches for
43
+ parts of Rails and common gems that redo work on every request, and the other minimizer
44
44
  parts.'
45
45
  executables:
46
46
  - rails-minify-ab
@@ -86,6 +86,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  requirements: []
87
87
  rubygems_version: 4.0.20
88
88
  specification_version: 4
89
- summary: Strict Active Record attribute methods, ZJIT after boot, and checks for callback
90
- problems
89
+ summary: Strict Active Record attribute methods, production profiling, and checks
90
+ for callback problems
91
91
  test_files: []