> The last time I checked, Mariano's test case above failed when added to the
> set of tests in the most recent code in master on github, and is
Unfortunately, I failed to push and only committed locally. The change
should now be in master. I would love it if you guys sent me a pull
request with your test.
> representative of the behavior I'm seeing in one of our applications. I
> don't have a test case for (potential) concurrency issues as I didn't nail
> anything specific down, and that sort of thing is hard to reproduce.
> However, I was thinking about the concurrency stuff a bit today while
> running some errands, and I had an idea:
>
> When executing a template, if instead of passing the original Writer
> (which is obviously not shared beween thread) between Codes, you passed
> something like a RenderContext that wrapped up the writer and any mutable
> state (like cached guards) that was related to the current rendering pass.
> Then you could keep the caching, make all fields on Codes final, and I
> think be very confident about thread safety. Just an idea I wanted to get
> out while it was fresh. If you'd be interested in this sort of approach,
> I'd be happy to put in a bit of time on an implementation, seems like it
> might be fun to do.
An interesting idea. I'm not sure how it would graph back onto the
Codes efficiently. It might make sense to just have a different
ObjectHandler that doesn't do the caching / guarding at all. It is
slower, but not complicated.
> I don't think there's any issue with changing the backing objects on
> mustache instances reducing performance due to cache misses, but I think
> it's worth pointing out that the use case could potentially be hard to
> avoid. Given that the defaultMustacheFactory caches instances, it's hard to
> get a new instance for something like a little utilitarian partial for a
Creating a default mustache factory is cheap, you can just use another
one and recompile. But, I see what you mean. I will reconsider whether
having that at the top level makes sense. It may make more sense to
cache that at a lower level.
> common UI element if you "decide" you have to change the type of backing
> object. Also, in some more complex application environments, you may not
> always have access to data in the same way. As an example, at Lulu we have
> to display summary information about books all the way from the creation
> process to when they're shipped to a customer. Even though the book might
> be displayed with the same UI and the same template in several places, the
> internal representation of the book changes many times along the way.
This is another case where it might make more sense to just use a
simpler, less aggressive object handler. I'll probably add one to make
this use case more natural and easier to reason about.
> While I'm rambling, let me also say thanks for the excellent mustache
> implementation for java, and also for introducing the template inheritance
> mechanism and proposing it as part of the spec. I think it's a really nice
> mechanism that fits well with the simple & logic-less approach of mustache
> while adding a ton of value. I'm looking forward to updating our templates
> to use it.
Thanks! I appreciate all the feedback and the use cases I haven't
thought about.
Sam