Skip to content
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

Global toggle to turn it off #31

Open
moonglum opened this issue Jun 29, 2014 · 6 comments
Open

Global toggle to turn it off #31

moonglum opened this issue Jun 29, 2014 · 6 comments

Comments

@moonglum
Copy link

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
Copy link
Collaborator

mbj commented Jun 29, 2014

@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.

@moonglum
Copy link
Author

Interesting – thanks for your feedback!

@mbj
Copy link
Collaborator

mbj commented Jun 30, 2014

@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.

@moonglum
Copy link
Author

I think Adamantium::Flat is really interesting. You are using that in Anima, right?

@mbj
Copy link
Collaborator

mbj commented Jun 30, 2014

@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).

@moonglum
Copy link
Author

Oh, cool. Have to look at Anima again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants