On Dec 13, 2010, at 09:43 , Alain Frisch wrote:

> On 12/12/2010 08:09 PM, Benedikt Meurer wrote:
>> The boxing involved is relevant, but boxing in general is not the
>> issue. In this special case, the "let nlen, n = if..." code requires
>> heap allocation, because of the way the pattern is compiled. This could
>> be fixed by moving the condition out of the code and using two if's to
>> select n/nlen separately (doesn't speed up that much). Fixing the
>> pattern compiler to handle these cases might be interesting for general
>> benefit.
> 
> Instead of duplicating the conditional, you could also push the assignments 
> to bound variables down the expression. For instance:
> 
> let (x, y) = if b then (u, v) else (v, u) in ...
> 
> can be replaced, conceptually, by:
> 
> let x = <dummy> in
> let y = <dummy> in
> if b then (x <- u; y <- v) else (x <- v; y <- u);
> ...
> 
> and similarly when the bound expression is a pattern matching.
> 
> 
> I've played with this a few months ago and could observe important speedups 
> (27%, 20%) on two micro-benchmarks.
> 
> The diff is really small:
> 
> http://caml.inria.fr/cgi-bin/viewcvs.cgi/ocaml/branches/inplace_let/bytecomp/matching.ml?rev=10475&sortby=date&r2=10475&r1=10474

Nice. But it would be even better to avoid the dummy, in your example

  let x = u in
  let y = v in
  if b then x <- v; y <- u

This does not only avoid the dummy, but would also allow lowering to "cmovcc" 
instructions in the backend selector (atleast for x86-32/64). 

> -- Alain

Benedikt
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to