Skip to content

Commit

Permalink
Move plumbing to enable yjit to inside the framework
Browse files Browse the repository at this point in the history
There is no reason to expose all those details to users and this
has the benefit that now are can ensure that the YJIT is enabled
after all initialization is done.
  • Loading branch information
rafaelfranca committed May 23, 2024
1 parent c906f75 commit 30e6a19
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
11 changes: 11 additions & 0 deletions guides/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Below are the default values associated with each target version. In cases of co
- [`config.active_record.postgresql_adapter_decode_dates`](#config-active-record-postgresql-adapter-decode-dates): `true`
- [`config.active_record.validate_migration_timestamps`](#config-active-record-validate-migration-timestamps): `true`
- [`config.active_storage.web_image_content_types`](#config-active-storage-web-image-content-types): `%w[image/png image/jpeg image/gif image/webp]`
- [`config.yjit`](#config-yjit): `true`

#### Default Values for Target Version 7.1

Expand Down Expand Up @@ -613,6 +614,16 @@ Used to easily add nested custom configuration to the application config object

See [Custom Configuration](#custom-configuration)

#### `config.yjit`

Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are
deploying to a memory constrained environment you may want to set this to `false`.

| Starting with version | The default value is |
| --------------------- | -------------------- |
| (original) | `false` |
| 7.2 | `true` |

### Configuring Assets

#### `config.assets.css_compressor`
Expand Down
5 changes: 4 additions & 1 deletion railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Configuration < ::Rails::Engine::Configuration
:content_security_policy_nonce_generator, :content_security_policy_nonce_directives,
:require_master_key, :credentials, :disable_sandbox, :sandbox_by_default,
:add_autoload_paths_to_load_path, :rake_eager_load, :server_timing, :log_file_size,
:dom_testing_default_html_version
:dom_testing_default_html_version, :yjit

attr_reader :encoding, :api_only, :loaded_config_version, :log_level

Expand Down Expand Up @@ -81,6 +81,7 @@ def initialize(*)
@rake_eager_load = false
@server_timing = false
@dom_testing_default_html_version = :html4
@yjit = false
end

# Loads default configuration values for a target version. This includes
Expand Down Expand Up @@ -318,6 +319,8 @@ def load_defaults(target_version)
when "7.2"
load_defaults "7.1"

self.yjit = true

if respond_to?(:active_job)
active_job.enqueue_after_transaction_commit = :default
end
Expand Down
6 changes: 6 additions & 0 deletions railties/lib/rails/application/finisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ def self.complete(_state)
ActiveSupport::DescendantsTracker.disable_clear!
end
end

initializer :enable_yjit do
if config.yjit && defined?(RubyVM::YJIT.enable)
RubyVM::YJIT.enable
end
end
end
end
end

This file was deleted.

1 change: 0 additions & 1 deletion railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
config/environments/test.rb
config/initializers/assets.rb
config/initializers/content_security_policy.rb
config/initializers/enable_yjit.rb
config/initializers/filter_parameter_logging.rb
config/initializers/inflections.rb
config/initializers/permissions_policy.rb
Expand Down
1 change: 0 additions & 1 deletion railties/test/generators/plugin_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
test/dummy/config/environments/production.rb
test/dummy/config/environments/test.rb
test/dummy/config/initializers/content_security_policy.rb
test/dummy/config/initializers/enable_yjit.rb
test/dummy/config/initializers/filter_parameter_logging.rb
test/dummy/config/initializers/inflections.rb
test/dummy/config/initializers/permissions_policy.rb
Expand Down

0 comments on commit 30e6a19

Please sign in to comment.