Menu

#124 Currying functions should be implicitly /**nocache**/

open
nobody
Evaluator (39)
5
2006-05-22
2006-05-22
No

There's a little-know feature of SDL that makes it very
easy to create functions that return functions. If a
function definition has more than one set of formal
arguments, it represents a function which binds the
first set of arguments and then returns another
function. Here's an example:

plusX(x)(y) { return x+y; };

Calling plusX with one argument returns another
function of one argument which will add the two
arguments together.

plus1 = plusX(1);
three = plus1(2);

Right now, either all levels of the function will be
cached or if the /**nocache**/ is used none will be cached.

We recently saw a case where a function like this was
being cached and was capturing a large value in the
outer call. This created a large result value with
many file references, and caused us some trouble by
taking up a lot of space in the graph log.

After seeing this it occurs to me that there's no real
value in caching the outer levels of such currying
functions. All they do is capture arguments into a new
closure for use later. They don't do any work at all,
and the round-trip to the cache server will certainly
be a waste. I propose making the outer call levels of
all such currying functions implicitly non-cached.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB