New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove ObectSpace dumping and start using inherited, it's faster. #4342
Conversation
561414c
to
4f20e3e
Compare
Hulk: benchmark +old-v-new : Prove to me my theory is right. |
I have done as you requested:
Here is my source because I know you bang on about it constantly being important: require "benchmark/ips"
require "set"
class A
def self.descendants
descendants = []
ObjectSpace.each_object(singleton_class) do |k|
descendants.unshift k unless k == self
end
descendants
end
end
class B
def self.inherited(const)
return catch_inheritance(const) do |const_|
catch_inheritance(const_)
end
end
#
def self.catch_inheritance(const)
const.define_singleton_method :inherited do |const_|
(@children ||= Set.new).add const_
if block_given?
yield const_
end
end
end
#
def self.descendants
@children ||= Set.new
out = @children.map(&:descendants)
out << self unless superclass == B
Set.new(out).flatten
end
end
Object.const_set(:A1, Class.new(A))
Object.const_set(:A2, Class.new(A))
Object.const_set(:A3, Class.new(A))
Object.const_set(:A4, Class.new(A))
Object.const_set(:A5, Class.new(A))
Object.const_set(:A6, Class.new(A))
Object.const_set(:A7, Class.new(A))
Object.const_set(:B1, Class.new(B))
Object.const_set(:B2, Class.new(B))
Object.const_set(:B3, Class.new(B))
Object.const_set(:B4, Class.new(B))
Object.const_set(:B5, Class.new(B))
Object.const_set(:B6, Class.new(B))
Object.const_set(:B7, Class.new(B))
Benchmark.ips do |x|
x.report("A") { A.descendants }
x.report("B") { B.descendants }
x.compare!
end You started the race slow but came out ahead so far I'm pretty sure you rigged the race car some how. You won though until I can prove otherwise. |
def find_converter_instance(klass) | ||
converters.find { |c| c.class == klass } || proc { raise "No converter for #{klass}" }.call | ||
converters.find { |klass_| klass_.instance_of?(klass) } || \ | ||
raise("No Converters found for #{klass}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should raise some Jekyll-specific error here.
Way faster! Thanks! 🎉 |
4f20e3e
to
70f741b
Compare
@jekyllbot: merge +dev |
…herited Merge pull request 4342
No description provided.