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

Pattern caching #32

Closed
minad opened this issue Aug 14, 2014 · 4 comments
Closed

Pattern caching #32

minad opened this issue Aug 14, 2014 · 4 comments

Comments

@minad
Copy link
Contributor

minad commented Aug 14, 2014

I am not perfectly sure if it makes sense in this library, but you could maybe provide a constructor which returns cached Mustermänner. But maybe you rather want to rely on Sinatra or the user?

Currently the docs say:

It's generally a good idea to reuse pattern objects, since as much computation as possible is happening during object creation, so that the actual matching or expanding is quite fast.

@rkh
Copy link
Member

rkh commented Aug 14, 2014

There is actually a cache built-in. But it only holds weak references, to not cause a memory leak.

2.1.2 :001 > x = Mustermann.new "/foo"
 => #<Mustermann::Sinatra:"/foo">
2.1.2 :002 > y = Mustermann.new "/foo"
 => #<Mustermann::Sinatra:"/foo">
2.1.2 :003 > x.object_id
 => 70336235790360
2.1.2 :004 > y.object_id
 => 70336235790360
2.1.2 :005 > x = y = nil
 => nil
2.1.2 :006 > GC.start
 => nil
2.1.2 :007 > x = Mustermann.new "/foo"
 => #<Mustermann::Sinatra:"/foo">
2.1.2 :008 > x.object_id
 => 70336230084880

@minad
Copy link
Contributor Author

minad commented Aug 14, 2014

GREAT! Please update the documentation. I think this can be closed then...

@minad minad closed this as completed Aug 14, 2014
@minad
Copy link
Contributor Author

minad commented Aug 14, 2014

Hmm, doesn't work for me (My thing runs only half as fast). Either it is not working or the gc kicks in all the time :(

@rkh
Copy link
Member

rkh commented Aug 14, 2014

Yeah, that might be. Which is why I'd rather not recommend relying on it.

What Ruby version are you on?

On Thu, Aug 14, 2014 at 5:01 PM, Daniel Mendler notifications@github.com
wrote:

Hmm, doesn't work for me (My thing runs only half as fast). Either it is
not working or the gc kicks in all the time :(


Reply to this email directly or view it on GitHub
#32 (comment).

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