adamantium
adamantium copied to clipboard
Global toggle to turn it off
I suggest to add a global switch to deactivate Adamantium. If it is activated, all calls to include Adamantium
will be noops.
Reasoning: @solnic and I talked about Adamantium when we met at RedDotRuby Conf. He said that one of the problems with Adamantium is that it has significant performance implications. Because of this, people like @mbj removed Adamantium when going to production. He said that Adamantium is more to help you learn and to check your applications not so much for having this functionality in production. We concluded that it should probably be a testing / linting tool rather than something running in production. With the proposed functionality, Adamantium would only be active when running the unit tests.
@mbj Only disables adamantium when its a problem and only very fine grained. Example is deep freezing big JSON / YAML parsed deeply nested trees. For my business logic admantium is fully active. Through I normally use Admamantium::Flat
before I disable it. The public visible side effect #frozen?
should not only be on testing as it can confuse other parts of the code. Shallow freezing with Adamantium::Flat
is highly recommended before removing adamantium or making it a noop. Its performance implications are very small compared to a noop.
Interesting – thanks for your feedback!
@moonglum Did you tried Adamantium::Flat
already? Its a really nice alternative in case deep freezing might reach into non freezable objects, or you care about the perf implications.
Its implementation is basically:
class MyClass
def self.new(*arguments)
super.freeze
end
end
This only touches the newly created object thats on stack / active cache line / whatever. Does not walk through your object graph causing costly cache misses.
I think Adamantium::Flat is really interesting. You are using that in Anima, right?
@moonglum no. Instances of Anima infected classes are not frozen by default. You can if you wanted via including Adamantium
or Adamantium::Flat
next to Anima.new(:my, :attribute)
.
Oh, cool. Have to look at Anima again!