Git Product home page Git Product logo

memoizable's People

Contributors

dkubb avatar mbj avatar sferik avatar trliner avatar ys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

memoizable's Issues

its not support ruby 3. because of : ruby_dep-1.5.0

Query List: ["memoizable"]
Query Gemcutter Dependency Endpoint API: memoizable
HTTP GET https://gems.ruby-china.com/api/v1/dependencies?gems=memoizable
HTTP 200 OK https://gems.ruby-china.com/api/v1/dependencies?gems=memoizable
Query List: []
Resolving dependencies....
ruby_dep-1.5.0 requires ruby version ~> 2.2, >= 2.2.5, which is incompatible with the current version, ruby 3.0.3p157
Bundler::InstallError: ruby_dep-1.5.0 requires ruby version ~> 2.2, >= 2.2.5, which is incompatible with the current version, ruby 3.0.3p157
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:249:in `block in ensure_specs_are_compatible!'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/spec_set.rb:136:in `each'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/spec_set.rb:136:in `each'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:246:in `ensure_specs_are_compatible!'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:83:in `block in run'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/process_lock.rb:12:in `block in lock'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/process_lock.rb:9:in `open'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/process_lock.rb:9:in `lock'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:71:in `run'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:23:in `install'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli/install.rb:60:in `run'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli.rb:253:in `block in install'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/settings.rb:131:in `temporary'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli.rb:252:in `install'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli.rb:31:in `dispatch'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli.rb:25:in `start'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/bundler-2.2.32/libexec/bundle:49:in `block in <top (required)>'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/friendly_errors.rb:103:in `with_friendly_errors'
  /home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/bundler-2.2.32/libexec/bundle:37:in `<top (required)>'
  /home/siwei/.asdf/installs/ruby/3.0.3/bin/bundle:23:in `load'
  /home/siwei/.asdf/installs/ruby/3.0.3/bin/bundle:23:in `<main>'

Calling memoized superclass method from memoized method results in hard to debug exception

require 'memoizable'

class A
  include Memoizable
  def foo
    :foo
  end
  memoize :foo
end

class B < A
  def foo
    super
  end
  memoize :foo
end

B.new.foo

Results in:

/home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:48:in `[]=': The method foo is already memoized (ArgumentError)
        from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:63:in `block (3 levels) in fetch'
        from /home/mbj/.gem/ruby/2.1.0/gems/thread_safe-0.1.3/lib/thread_safe/cache.rb:51:in `fetch'
        from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:62:in `block (2 levels) in fetch'
        from /home/mbj/.rubies/ruby-2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
        from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:61:in `block in fetch'
        from /home/mbj/.gem/ruby/2.1.0/gems/thread_safe-0.1.3/lib/thread_safe/cache.rb:51:in `fetch'
        from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:60:in `fetch'
        from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/method_builder.rb:116:in `block (2 levels) in create_memoized_method'
        from repro.rb:17:in `<main>'

Root cause: Memory#[]= gets hit twice and the memory rightfully raises here.

IMHO we should detect this situation when overriding the memoizer in parent class.

Lazy loader / auto include

Hello,
I wanted to make memoize available across the project and I came up with this:

Class.class_eval do
  def memoize *args
    include ::Memoizable
    memoize *args
  end
end

But that's a bit ugly solution so just wanted to ask how would you recommend achieving this?

Support for parameterized methods

Hello.

I just finished publishing https://github.com/KoanHealth/forget-me-not. While tipping the hat to @sferik, he pointed me to this gem. I agree with him that the world doesn't need these ideas developed in two places, so I'd like to offer to help in any way that I can.

Two things that I incorporated into forget-me-not are arguments and caching.

Arguments are pretty straightforward.

Caching is intended to be more of a system wide memoization. We started from @sferik's code to enable some classes that chew on aggregate medical claims data to share the results of their initial queries.

My big question is can these two ideas find a home in this gem?

Deprecation message

".rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `call': [DEPRECATION] #verified is deprecated. Use #verified? instead."

I don'y have the memoizable gem within my project so I'm not sure what might be generating the warning.

My rake task still runs - it's just outputting this message for each record I process.

I'm running Rails 4.1.4 and using Postgres for my database.

Cacheable capability?

One thing that got lost in the hubbub over memoizing methods with arguments was the caching capability in forget-me-not which has a similar interface (even if the intent is wildly different).

I know this is a somewhat odd fit in a project called memoizable, but the two ideas occupy a similar region of headspace, so I thought it made sense to combine them in a single gem.

There's a pretty decent write-up of the intent and capabilities of cacheable on the forget-me-not project page. Is it possible that this idea can find a home here?

Memoization of singleton methods raises NoMethodError

I was messing around in irb (actually, pry) and felt 😕 when I attempted to memoize a method outside of a class context:

[1] pry(main)> require 'memoizable'
=> true
[2] pry(main)> include Memoizable
=> Object
[3] pry(main)> def foo; end
=> nil
[4] pry(main)> memoize :foo
NoMethodError: undefined method `each' for :foo:Symbol
from /Users/e/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/memoizable-0.2.0/lib/memoizable/memory.rb:59:in `set'

This is the line where the error is occurring, which I believe is being called from here.

This error occurs when attempting to memoize singleton methods, defined on an instance of a class:

require 'memoizable'

class Foo
  include Memoizable
end

foo = Foo.new
def foo.bar; end
foo.memoize :bar

To resolve this issue we must first address the following question: Should one be able to memoize singleton methods?

If the answer is “yes”, resolving this issue entails adding that feature.

If the answer is “no”, we can just raise a better error message.

Possible performance issues?

I noticed a massive slow down in ROM after upgrading to latest adamantium/memoizable. Do you guys think some recent changes may affect performance (ThreadSafe maybe?).

Memoizing methods with implicit blocks may surprise user

Consider the following code:

class Foo

  def bar
    yield
  end
  memoize :bar

  def baz
    yield if block_given?
  end
  memoize :baz

end

Currently, if a user memoizes a method with an explicit block (or any explicit parameters), they will receive an error at load time (Memoizable::MethodBuilder::InvalidArityError). However, if a method yields to an implicit block, users will receive a LocalJumpError (in the case of bar) or—worse—no error at all (in the case of baz). This behavior may surprise users, who don’t expect memoize to modify the behavior of their methods.

This seems bad but I can’t think of a good solution so I’m opening this issue for discussion. Curious to hear your thoughts…

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.