-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial batch of swapping Active Support extensions for in-house alte…
…rnatives (WIP) (#881) * Initial batch of swapping Active Support extensions for in-house alternatives - new `within?` method offers some unique semantics * Refactor core exts, ensure tests pass * Fix more tests, add string indentation - Remove unneeded Active Support extensions once thought to be necessary for Thor actions * Move core extensions to new Foundation gem…more to follow! * Add more functionality to Foundation - translation safety - module nesting - also clean up outdated subclass tracking for route class files * Support Ruby 3+ pattern matching for Collection and Resource::Base * Convert many Foundation extensions to refinements for cleaner monkeypatching - new .() and .with() features for Symbol * Load in HashWithDotAccess 2.0, remove AS dependency of indifferent access * Add deep_dup to Foundation, remove AS dependency * Move HashWithDotAccess dep over to Foundation, remove more AS deps * Rewrite Current and "class attributes" to remove AS dep * Remove Active Model, AS callbacks, spurious reference to indifferent access * Move Ansi color helpers to Foundation, remove colorator dep * various fixes * fix spurious references to colorator in test * Add new `Bridgetown::Inflector` based on `Dry::Inflector` * Change classname based on inflection rules * more inflection fixes * Ensure tests pass with inflector equality check * Add `foundation` helper so refinements are activated for any wrapped object * Fix website lock * Backtrack on odd symbol syntax * Include `foundation` helper in more contexts * Fix additional symbol syntax in backtracking * Support multiple `foundation` arguments, use SimpleDelegator * Backtrack from `foundation` helper, use base module system * Set up packaging system using the Inclusive gem * Remove `with` Symbol refinement, no use for it
- Loading branch information
1 parent
c428f02
commit 98b6a7b
Showing
92 changed files
with
1,186 additions
and
443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "bundler" | ||
Bundler.setup | ||
require "benchmark/ips" | ||
require "active_support/core_ext/hash/indifferent_access" | ||
require "hash_with_dot_access" | ||
|
||
class User < HashWithDotAccess::Hash | ||
end | ||
|
||
user = User.new({ address: { category: { desc: "Urban" } } }) | ||
|
||
using HashWithDotAccess::Refinements | ||
|
||
# Enable and start GC before each job run. Disable GC afterwards. | ||
# | ||
# Inspired by https://www.omniref.com/ruby/2.2.1/symbols/Benchmark/bm?#annotation=4095926&line=182 | ||
class GCSuite | ||
def warming(*) | ||
run_gc | ||
end | ||
|
||
def running(*) | ||
run_gc | ||
end | ||
|
||
def warmup_stats(*); end | ||
|
||
def add_report(*); end | ||
|
||
private | ||
|
||
def run_gc | ||
GC.enable | ||
GC.start | ||
GC.disable | ||
end | ||
end | ||
|
||
suite = GCSuite.new | ||
|
||
Benchmark.ips do |x| | ||
x.config(suite:, time: 1, warmup: 1) | ||
|
||
x.report("standard hash") do | ||
h = { "foo" => "bar" } | ||
h["foo"] | ||
end | ||
x.report("standard hash with fetch") do | ||
h = { "foo" => "bar" } | ||
h.fetch("foo", nil) | ||
end | ||
x.report("standard hash - symbol keys") do | ||
h = { foo: "bar" } | ||
h[:foo] | ||
end | ||
x.report("standard hash with fetch - symbol keys") do | ||
h = { foo: "bar" } | ||
h.fetch(:foo, nil) | ||
end | ||
x.report("hash with indifferent access string") do | ||
h = { "foo" => "bar" }.with_indifferent_access | ||
h["foo"] | ||
end | ||
x.report("hash with indifferent access symbol") do | ||
h = { "foo" => "bar" }.with_indifferent_access | ||
h[:foo] | ||
end | ||
x.report("hash with indifferent access via new method") do | ||
h = ActiveSupport::HashWithIndifferentAccess.new({ "foo" => "bar" }) | ||
h[:foo] | ||
end | ||
# x.report("hash with indifferent access via []") do | ||
# h = ActiveSupport::HashWithIndifferentAccess[{ "foo" => "bar" }] | ||
# h[:foo] | ||
# end | ||
x.report("hash as_dots and symbol access") do | ||
h = { foo: "bar" }.as_dots | ||
h[:foo] | ||
end | ||
x.report("hash as_dots and method access") do | ||
h = { foo: "bar" }.as_dots | ||
h.foo | ||
end | ||
x.report("hash with dot access new method, string init, and symbol access") do | ||
h = HashWithDotAccess::Hash.new({ "foo" => "bar" }) | ||
h[:foo] | ||
end | ||
x.report("hash with dot access new method, symbol init, and method access") do | ||
h = HashWithDotAccess::Hash.new(foo: "bar") | ||
h.foo | ||
end | ||
x.report("hash with dot access new method, string access") do | ||
h = HashWithDotAccess::Hash.new({ "foo" => "bar" }) | ||
h["foo"] | ||
end | ||
user = { address: { category: { desc: "Urban" } } } | ||
x.report("nested symbols") do | ||
user[:address][:category][:desc] | ||
end | ||
userd = User.new({ address: { category: { desc: "Urban" } } }) | ||
x.report("nested dots") do | ||
userd.address.category.desc | ||
end | ||
x.compare! | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.