adamantium icon indicating copy to clipboard operation
adamantium copied to clipboard

Memoize methods that depend on instance state automatically

Open dkubb opened this issue 12 years ago • 4 comments

An immutable object's state never changes, so the #hash, #inspect and #to_s methods are idempotent. These methods should be memoized by default.

dkubb avatar Jan 06 '13 08:01 dkubb

I like this change.

We have to communicate methods need to be present / changed before Adamantium is included. Especially in conjunction with Equalizer.

Correct:

class Foo
  include Adamantium, Equalizer.new(:foo)
end

Incorrect:

class Foo
  include Equalizer.new(:foo), Adamantium
end

Module#include does include modules in reverse order.

mbj avatar Jan 06 '13 12:01 mbj

@mbj sure, the first thing we could do show examples using include on separate lines, then it's more clear the ordering of things. We can have an "advanced" section showing this one-liner, which includes Equalizer first then Adamantium.

dkubb avatar Jan 06 '13 17:01 dkubb

I just remember a chat conversation in #jruby, we improved performance on rack hashes with using separate String subclasses for keys that freezed contents and cachesObject#hash I lost the gist the guy created but we had around 20% speedup.

mbj avatar Jan 06 '13 17:01 mbj

@mbj wdyt about https://github.com/dkubb/adamantium/pull/25 ?

dkubb avatar Dec 16 '13 08:12 dkubb