incubator-esme-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vassil Dichev <vdic...@apache.org>
Subject Memory allocation and lazy vals
Date Sat, 28 Nov 2009 13:36:15 GMT
I found a weird thing today. Lazy vals don't act lazy under certain conditions.

For those who are not familiar with lazy values, they are values which:
- are calculated on demand
- are memoized so that the next invocation won't compute the same code again

You can find a nice article about behavior of lazy vals here:
http://blogs.tedneward.com/2009/03/29/Laziness+In+Scala.aspx

In ESME's case, lazy values are used to format a message into XML and
XHTML only once per instance (does that ring any bells?). What happens
in Message, though, is that digestedXHTML, toXml and originalXml,
which are all lazy, are executed again and again on each consecutive
call! I'm not sure why that is, but if I change the access of object
text to returning a hardcoded value, it works as expected, and gets
evaluated only once.

I'm currently trying to find the reason for this phenomenon and find
workarounds. This detail undermines our implementation of caching
messages, but at least now we know what causes the strange behavior
observed by Markus.

Mime
View raw message