Eugene Kenny
7af59e16a2
Use transform_values in a few more places
...
It's faster on Ruby 2.7+ since it avoids rehashing the keys.
2020-09-08 01:34:41 +01:00
Jonathan Hefner
5611f4b430
Anchor BacktraceCleaner gem filter regexp
...
This ensures the default gem filter does not affect backtrace lines that
have a subpath incidentally matching a gem path.
Fixes #40196 .
2020-09-07 16:44:57 -05:00
Kasper Timm Hansen
0e5f9a0a42
Merge pull request #40171 from vinistock/reduce_allocations_in_cache_methods
...
Reduce allocations in expanded_version and expanded_key
2020-09-05 14:32:36 +02:00
Vinicius Stock
483aaaddfa
Prevent returning nil when compacting array
2020-09-03 16:08:24 -04:00
Vinicius Stock
061092a4ba
Reduce allocations in expanded_version and expanded_key
2020-09-03 14:00:43 -04:00
John Hawthorn
15874514fa
Use real_mod_name on check for removed module
...
Previously this check could break if `name` was overridden on the module
we were checking.
2020-09-02 14:08:45 -07:00
Rafael França
61716e1fde
Merge pull request #39350 from jaynetics/fix_rounding_of_custom_formatted_negative_amounts
...
Fix rounding of custom-formatted negative amounts
2020-08-26 16:08:55 -04:00
Rafael França
7bd416363a
Merge pull request #38699 from jasonyork/master
...
Add ActiveSupport::Duration conversion methods
2020-08-26 13:49:21 -04:00
Rafael Mendonça França
ce5fe05bc5
Use super instead of self
...
This will make clear what is the expected behavior of that method call.
2020-08-26 17:44:44 +00:00
Akshay Birajdar
a12a2707ac
Implement #inspect for ActiveSupport::OrderedOptions
2020-08-26 21:50:09 +05:30
Jason York
a2535d9fe9
Rename prefix to in_* and update CHANGELOG
2020-08-26 09:36:03 -05:00
Jason York
7bd9603778
Add ActiveSupport::Duration conversion methods
2020-08-26 09:35:09 -05:00
Rafael França
ee6ee11b01
Merge pull request #40033 from dpep/deep-dup
...
deep dup optimization
2020-08-25 20:25:09 -04:00
Akshay Birajdar
07e6270a27
Corrects the config object class [ci skip]
2020-08-23 00:53:22 +05:30
Daniel Pepper
964e7ad156
deep dup
...
Is there a reason we're only taking this short cut for frozen strings and not other immutable objects commonly used as hash keys (eg. symbols and integers)?
initial tests suggest a ~30% performance improvement...
```
require 'benchmark'
class Object
def deep_dup
dup
end
alias deep_dup_all deep_dup
end
class Hash
def deep_dup
hash = dup
each_pair do |key, value|
if key.frozen? && ::String === key
hash[key] = value.deep_dup
else
hash.delete(key)
hash[key.deep_dup] = value.deep_dup
end
end
hash
end
def deep_dup_all
hash = dup
each_pair do |key, value|
if key.frozen?
hash[key] = value.deep_dup_all
else
hash.delete(key)
hash[key.deep_dup_all] = value.deep_dup_all
end
end
hash
end
end
data = Hash[('aaa'..'zzz').map {|k| [k.to_sym, k]}]
control = Benchmark.realtime do
30.times { data.deep_dup }
end
experiment = Benchmark.realtime do
30.times { data.deep_dup_all }
end
puts "%.3f v %.3f => %d%% speed up" % [ control, experiment, (control - experiment) / control * 100 ]
```
2020-08-17 15:24:47 -07:00
Alexey Savin
80f59eadb4
Make Enumerable.pluck
faster for single key
2020-08-06 21:22:20 +03:00
Rajesh Sharma
4a552c3ab9
Fix option not being passed with fetch_multi
...
In redis cache store, options to `fetch_multi` are passed correctly to
`write_multi` but not to `read_multi`. This causes cache always to be missed
when passing `namespace` option to it.
2020-07-26 08:34:30 +02:00
maxgurewitz
73ba6faa36
prevents redundant memcached compression
...
- Disables Dalli compression in MemCacheStore.
- Fixes issue where redundant compression in Dalli can cause values to
either be compressed twice, or compressed when they fall below the
specified compression threshold.
2020-07-25 12:59:39 -07:00
maxgurewitz
f1fb097a74
prevents raw redis and memcached compression
...
- Fixes issue where reads with raw: true using redis or memcached cache
store, will compress values on reads.
- Should speed up raw cache reads by preventing unnecessary cpu intensive
operation.
2020-07-24 11:56:43 -07:00
Eugene Kenny
19d8578361
Add a regression test for per-fiber tagged logging
...
Followup to 978421abd83d45b72e299f50a4fb324fcbdb3e00.
2020-07-02 22:37:23 +01:00
Eugene Kenny
c3913e580c
Revert "Cache tags_text to avoid computing tags each time when logging"
...
This reverts commit 05060ddba1
.
Tags are per-fiber, so they can't be cached in an instance variable.
2020-07-02 22:30:46 +01:00
Jean Boussier
b0cc7d985e
Refactor MemoryStore to use Hash ordering rather than key access times
...
This is mainly to simplify the code and use less memory, as large hash can use quite a lot:
```ruby
>> ObjectSpace.memsize_of(1000.times.map { |i| [i, i]}.to_h)
=> 28768
>> ObjectSpace.memsize_of(10_000.times.map { |i| [i, i]}.to_h)
=> 458848
```
The performance is mostly not impacted, if not slightly better:
```ruby
require 'benchmark/ips'
require 'active_support/all'
@store = ActiveSupport::Cache::MemoryStore.new
@store.write("small", "small")
Benchmark.ips do |x|
x.report("read:miss") { @store.read("miss") }
x.report("read:small") { @store.read("small") }
x.report("write:small") { @store.write("small", "small") }
end
```
6.0.3.2:
```
Warming up --------------------------------------
read:miss 42.466k i/100ms
read:small 25.315k i/100ms
write:small 17.826k i/100ms
Calculating -------------------------------------
read:miss 426.923k (± 1.9%) i/s - 2.166M in 5.074890s
read:small 248.518k (± 2.7%) i/s - 1.266M in 5.097049s
write:small 180.388k (± 1.6%) i/s - 909.126k in 5.041238s
```
This branch:
```
Warming up --------------------------------------
read:miss 42.040k i/100ms
read:small 28.364k i/100ms
write:small 19.361k i/100ms
Calculating -------------------------------------
read:miss 417.814k (± 2.1%) i/s - 2.102M in 5.033186s
read:small 278.950k (± 2.8%) i/s - 1.418M in 5.088135s
write:small 193.384k (± 1.8%) i/s - 968.050k in 5.007446s
```
2020-07-01 12:32:55 +02:00
Haroon Ahmed
d091b9ccee
Improve the docs for ordered options
2020-06-30 22:08:59 +01:00
Jean Boussier
12f3f11f61
Use URI::DEFAULT_PARSER rather than instantiate a new one
2020-06-29 23:06:34 +02:00
Eugene Kenny
cf1881237a
Remove unnecessary rescue from safe_constantize
...
The error being handled here was removed in
01c9782fa2
.
2020-06-29 16:29:50 +01:00
Jean Boussier
8044d06b4d
Use LoadError#original_message if available in safe_constantize
2020-06-28 19:29:57 +02:00
colorbox
3758274b3b
Fix an error for FileStore.cleanup
when using Sprockets
...
### Summary
This PR fixes `NoMethodError` for `ActiveSupport::Cache::FileStore.cleanup` when using [Sprockets](https://github.com/rails/sprockets ).
`FileStore.cleanup` assumes entry object is a `Cache::Entry`.
An entry obejct is returned from `FileStore.read_entry` method.
If `FileStore.read_entry` returns object that cannot respond to `expired?` method, `FileStore.cleanup` will fail.
Sprockets generates cache file in tmp/cache/assets.
If `FileStore.read_entry` gets these Sprocket's cache file, this method creates entry object which cannot respond to `expired?` method.
In my project, this error occured and failed to execute `ActiveSupport::Cache::FileStore.cleanup`.
This PR adds a `is_a?` checking to entry object in `read_entry` method.
2020-06-25 23:58:30 +09:00
Yasuo Honda
fdbc55b9d5
Use Array(ActiveSupport::ToJsonWithActiveSupportEncoder)#to_json and Hash(ActiveSupport::ToJsonWithActiveSupportEncoder)#to_json for Ruby 2.8.0
...
This pull request addresses failures at https://buildkite.com/rails/rails/builds/70219#79d96882-6c51-4854-8cab-28f50ac8bca1
According to https://bugs.ruby-lang.org/issues/16973 This is an expected change in Ruby.
These failures has been addressed by changing the order of prepend as suggested.
```diff
% git diff
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 30a3b8e5a0..1328041bf7 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -186,6 +186,8 @@ def test_hash_should_pass_encoding_options_to_children_in_to_json
country: "UK"
}
}
+ p person.method(:to_json)
+ pp person.class.ancestors
json = person.to_json only: [:address, :city]
assert_equal(%({"address":{"city":"London"}}), json)
@@ -287,6 +289,8 @@ def test_array_to_json_should_not_keep_options_around
f.bar = "world"
array = [f, { "foo" => "other_foo", "test" => "other_test" }]
+ p array.method(:to_json)
+ pp array.class.ancestors
assert_equal([{ "foo" => "hello", "bar" => "world" },
{ "foo" => "other_foo", "test" => "other_test" }], ActiveSupport::JSON.decode(array.to_json))
end
%
```
* Ruby 2.8.0 without this fix uses `Array(JSON::Ext::Generator::GeneratorMethods::Array)#to_json`, which should use `Array(ActiveSupport::ToJsonWithActiveSupportEncoder)#to_json`
```
% bin/test test/json/encoding_test.rb -n test_array_to_json_should_not_keep_options_around
Run options: -n test_array_to_json_should_not_keep_options_around --seed 33311
[Array,
JSON::Ext::Generator::GeneratorMethods::Array,
ActiveSupport::ToJsonWithActiveSupportEncoder,
Enumerable,
ActiveSupport::ToJsonWithActiveSupportEncoder,
Object,
JSON::Ext::Generator::GeneratorMethods::Object,
ActiveSupport::Tryable,
Kernel,
BasicObject]
F
Failure:
TestJSONEncoding#test_array_to_json_should_not_keep_options_around [/Users/yahonda/src/github.com/rails/rails/activesupport/test/json/encoding_test.rb:294]:
--- expected
+++ actual
@@ -1 +1 @@
-[{"foo"=>"hello", "bar"=>"world"}, {"foo"=>"other_foo", "test"=>"other_test"}]
+["#<TestJSONEncoding::CustomWithOptions:0xXXXXXX>", {"foo"=>"other_foo", "test"=>"other_test"}]
bin/test test/json/encoding_test.rb:286
Finished in 0.015486s, 64.5745 runs/s, 64.5745 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
%
```
* Ruby 2.8.0 with this fix uses `Array(ActiveSupport::ToJsonWithActiveSupportEncoder)#to_json`
```
% bin/test test/json/encoding_test.rb -n test_array_to_json_should_not_keep_options_around
Run options: -n test_array_to_json_should_not_keep_options_around --seed 12193
[ActiveSupport::ToJsonWithActiveSupportEncoder,
Array,
JSON::Ext::Generator::GeneratorMethods::Array,
ActiveSupport::ToJsonWithActiveSupportEncoder,
Enumerable,
ActiveSupport::ToJsonWithActiveSupportEncoder,
Object,
JSON::Ext::Generator::GeneratorMethods::Object,
ActiveSupport::Tryable,
Kernel,
BasicObject]
.
Finished in 0.008070s, 123.9157 runs/s, 123.9157 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
%
```
* Ruby 2.8.0 without this fix uses `Hash(JSON::Ext::Generator::GeneratorMethods::Hash)#to_json`, which should use `Hash(ActiveSupport::ToJsonWithActiveSupportEncoder)#to_json`
```
% bin/test test/json/encoding_test.rb -n test_hash_should_pass_encoding_options_to_children_in_to_json
Run options: -n test_hash_should_pass_encoding_options_to_children_in_to_json --seed 18064
[Hash,
JSON::Ext::Generator::GeneratorMethods::Hash,
ActiveSupport::ToJsonWithActiveSupportEncoder,
Enumerable,
ActiveSupport::ToJsonWithActiveSupportEncoder,
Object,
JSON::Ext::Generator::GeneratorMethods::Object,
ActiveSupport::Tryable,
Kernel,
BasicObject]
F
Failure:
TestJSONEncoding#test_hash_should_pass_encoding_options_to_children_in_to_json [/Users/yahonda/src/github.com/rails/rails/activesupport/test/json/encoding_test.rb:193]:
--- expected
+++ actual
@@ -1 +1 @@
-"{\"address\":{\"city\":\"London\"}}"
+"{\"name\":\"John\",\"address\":{\"city\":\"London\",\"country\":\"UK\"}}"
bin/test test/json/encoding_test.rb:181
Finished in 0.015009s, 66.6267 runs/s, 66.6267 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
%
```
* Ruby 2.8.0 with this fix uses `Hash(ActiveSupport::ToJsonWithActiveSupportEncoder)#to_json`
```
% bin/test test/json/encoding_test.rb -n test_hash_should_pass_encoding_options_to_children_in_to_json
Run options: -n test_hash_should_pass_encoding_options_to_children_in_to_json --seed 56794
[ActiveSupport::ToJsonWithActiveSupportEncoder,
Hash,
JSON::Ext::Generator::GeneratorMethods::Hash,
ActiveSupport::ToJsonWithActiveSupportEncoder,
Enumerable,
ActiveSupport::ToJsonWithActiveSupportEncoder,
Object,
JSON::Ext::Generator::GeneratorMethods::Object,
ActiveSupport::Tryable,
Kernel,
BasicObject]
.
Finished in 0.007434s, 134.5171 runs/s, 134.5171 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
%
```
Refer
https://github.com/ruby/ruby/pull/3181
https://github.com/ruby/ruby/pull/2936
https://bugs.ruby-lang.org/issues/9573
https://github.com/rails/rails/pull/19413
2020-06-22 23:44:24 +09:00
Ryuta Kamizono
d6a9002824
Use method_defined?
instead of respond_to?
2020-06-19 20:32:40 +09:00
Ryuta Kamizono
ae8f7b0d59
Use native Hash#except
if it is defined
...
Now Ruby master has native `Hash#except`.
https://bugs.ruby-lang.org/issues/15822
2020-06-19 11:47:12 +09:00
Ryuta Kamizono
528b62e386
Address to false negative for Performance/DeletePrefix,DeleteSuffix
...
Follow up to c07dff7227
.
Actually it is not the cop's fault, but we mistakenly use `^`, `$`, and
`\Z` in much places, the cop doesn't correct those conservatively.
I've checked all those usage and replaced all safe ones.
2020-06-14 13:04:47 +09:00
Ryuta Kamizono
37c19f7ebc
Fix Active Support failure for redis 4.2.0 with Ruby 2.8.0-dev
2020-06-10 09:25:03 +09:00
Ryuta Kamizono
c07dff7227
Auto-correct for delete_prefix
/delete_suffix
...
Follow up to #39409 .
2020-06-05 12:40:39 +09:00
Yoshiyuki Kinjo
28d1ea0e49
remove redundant require: follow #39142
2020-06-04 12:21:54 +09:00
Aaron Patterson
35fe9bc0aa
Merge pull request #39477 from p8/improve-inspect
...
Make custom inspect methods more consistent
2020-06-03 10:43:35 -07:00
Eugene Kenny
b93608c059
Merge pull request #39505 from jonathanhefner/alias-subclasses-as-direct_descendants
...
Alias direct_descendants as subclasses
2020-06-03 10:26:34 +01:00
Jonathan Hefner
8f8aa857e0
Alias direct_descendants as subclasses
...
This alias overrides Class#subclasses. Thus calls to `subclasses` get a
free performance boost when the class extends DescendantsTracker.
2020-06-02 22:57:48 -05:00
Eugene Kenny
a7d2f60f3a
Merge pull request #39049 from krzysiek1507/fix/hash-with-indifferent-access-update
...
Use size == 1 instead of one? to check hashes count in HashWithIndifferentAccess#update
2020-06-02 02:11:53 +01:00
Kasper Timm Hansen
3b953da779
Catch Time.zone before TestHelper resets it to UTC
...
This is most easiest done by switching to before_setup, which fits since
we're also testing the ordering of the reset calls provided by the
TestHelper.
2020-06-02 01:31:14 +02:00
Kasper Timm Hansen
81b6ca0970
Merge pull request #39493 from rails/fix-current-attributes-reset-in-models
...
Reset ActiveSupport::CurrentAttributes even where executor doesn't wrap
2020-06-02 00:36:30 +02:00
David Heinemeier Hansson
36a33d721c
Needlessly tight dependency spec
...
Let it float, unless there's a specific threat to the opposite.
2020-05-31 16:45:37 -07:00
Kasper Timm Hansen
c962409ba6
Reset ActiveSupport::CurrentAttributes even where executor doesn't wrap
...
Currently there's a problem with ActiveSupport::CurrentAttributes where
they don't reset unless there's a controller or a job executing.
This is because we correctly hook into the controller/job executor to
reset them.
However, we were missing plain tests, so this is that.
2020-05-31 22:26:24 +02:00
Petrik
74cb9a6f38
Make inspect look more like regular Object#inspect
...
Move the # outside the < > just like regular Object#inspect
2020-05-29 21:53:35 +02:00
Ryuta Kamizono
c65864cdca
Prefer no allocation start/end_with?
over String#[] ==
2020-05-29 10:20:13 +09:00
Alexander Shemetovskiy
3d1b9389a9
Test that Array#extract_options! extracts ActiveSupport::OrderedOptions
2020-05-24 16:59:42 -04:00
Ryuta Kamizono
dc94a753d1
require "active_support/core_ext/symbol/starts_ends_with" for Ruby 2.6
...
And use `Symbol#[]` to strip suffix to avoid intermediate string
allocation.
2020-05-25 05:24:44 +09:00
fatkodima
e24d6ecbfd
Update rubocop-performance gem and enable Performance/DeletePrefix and Performance/DeleteSuffix cops
2020-05-24 12:51:35 +03:00
Eugene Kenny
537b071002
Copy options before delegating in with_options
...
cd31e113c0
switched to passing options as
keyword arguments, which always creates a new hash.
9e4ff29f74
removed a now-unnecessary call
to `dup`, since the options could no longer be accidentally mutated.
a55620f3fa
switched back to passing
options as a positional argument for Ruby < 2.7, but didn't restore the
call to `dup`, which meant that the same options hash was now passed
with every method call and mutations leaked from one call to another.
2020-05-23 22:47:48 +01:00
Mads Ohm Larsen
e2a2ee008b
Decoding JSON dates should respect newlines
2020-05-21 13:04:01 +02:00
Jannosch Müller
31575b39ca
Fix rounding of custom-formatted negative amounts
...
closes #39349
2020-05-20 12:34:20 +02:00