Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Avoid raising ContextMiss when testing for key presence. #137

Merged
merged 1 commit into from

4 participants

@tomafro

Raising ContextMiss can be expensive. The error message includes @stack.inspect, which depending on the size and content of the stack can be very costly to generate. Defaulting to false for has_key? context misses retains the same behaviour without incurring this cost penalty.

@tomafro tomafro Avoid raising ContextMiss when testing for key presence.
Raising ContextMiss can be expensive.  The error message includes `@stack.inspect`, which depending on the size and content of the stack can be very costly to generate.  Defaulting to false for has_key? context misses retains the same behaviour without incurring this cost penalty.
eeff493
@mdavidn

:+1:

My application wastes 55% of its CPU time in Mustache::Context#has_key?, mostly in @stack.inspect.

Is this gem unmaintained?

@locks locks merged commit 97b6550 into mustache:master
@locks
Owner

Not anymore, @mdavidn.

@tomafro

Thanks for merging @locks. I think that breaks my record for longest wait for a pull request to be accepted!

@locks
Owner

@tomafro sharpening my necromancing skills ;P Thanks for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 23, 2012
  1. @tomafro

    Avoid raising ContextMiss when testing for key presence.

    tomafro authored
    Raising ContextMiss can be expensive.  The error message includes `@stack.inspect`, which depending on the size and content of the stack can be very costly to generate.  Defaulting to false for has_key? context misses retains the same behaviour without incurring this cost penalty.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/mustache/context.rb
View
2  lib/mustache/context.rb
@@ -80,7 +80,7 @@ def [](name)
# Do we know about a particular key? In other words, will calling
# `context[key]` give us a result that was set. Basically.
def has_key?(key)
- !!fetch(key)
+ !!fetch(key, false)
rescue ContextMiss
false
end
Something went wrong with that request. Please try again.