caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Performance of immediate objects
@ 2006-07-11 14:10 Chris King
  2006-07-12  0:51 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: Chris King @ 2006-07-11 14:10 UTC (permalink / raw)
  To: O'Caml Mailing List

Is there a substantial difference to the way in which

class foo (i:int) = object
 val v = i
 method bar = v
end

let mk_foo i = new foo i

and

let mk_foo (i:int) = object
 val v = i
 method bar = v
end

are compiled?  I've run a couple tests with the above and immediate
objects seem to be about 15% slower than classes.  Is this because a
new method table is created for the immediate object every time or is
that the case for classes also?

- Chris King


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Performance of immediate objects
  2006-07-11 14:10 Performance of immediate objects Chris King
@ 2006-07-12  0:51 ` Jacques Garrigue
  2006-07-12  4:08   ` Chris King
  0 siblings, 1 reply; 3+ messages in thread
From: Jacques Garrigue @ 2006-07-12  0:51 UTC (permalink / raw)
  To: colanderman; +Cc: caml-list

From: "Chris King" <colanderman@gmail.com>

> Is there a substantial difference to the way in which
> 
> class foo (i:int) = object
>  val v = i
>  method bar = v
> end
> 
> let mk_foo i = new foo i
> 
> and
> 
> let mk_foo (i:int) = object
>  val v = i
>  method bar = v
> end
> 
> are compiled?  I've run a couple tests with the above and immediate
> objects seem to be about 15% slower than classes.  Is this because a
> new method table is created for the immediate object every time or is
> that the case for classes also?

Certainly not. It would not be a 15% slowdown, but rather 10000%.
Initialization occurs only once, but one needs to check whether it was
done every time an object is created.
However, the 15% slowndown is for bytecode. For native code this is a
15% speedup. Guess which one we try to optimize.

Jacques Garrigue


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Performance of immediate objects
  2006-07-12  0:51 ` [Caml-list] " Jacques Garrigue
@ 2006-07-12  4:08   ` Chris King
  0 siblings, 0 replies; 3+ messages in thread
From: Chris King @ 2006-07-12  4:08 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: caml-list

On 7/11/06, Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> wrote:
> Initialization occurs only once, but one needs to check whether it was
> done every time an object is created.

Thanks, now the assembly output makes more sense to me.  I saw the
initialization code in the mk_foo function but didn't realize that it
was executed only once.

- Chris King


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-07-12  4:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-11 14:10 Performance of immediate objects Chris King
2006-07-12  0:51 ` [Caml-list] " Jacques Garrigue
2006-07-12  4:08   ` Chris King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).