[Vm-dev] Object basicNew vs object shallowCopy

Eliot Miranda eliot.miranda at gmail.com
Sat Jul 30 05:48:52 UTC 2016


Hi Denis,

    the difference us because basicNew[:] are implemented with machine code primitives whereas shallowCopy is an interpreter primitive and machine code primitives are much faster to invoke.  I could add a machine code shallowCopy primitive that would handle common cases and exclude the complex ones (CompiledMethod and Context, because they contain hidden JIT state that must not be copied).  How important is shallowCopy performance to you?

_,,,^..^,,,_ (phone)

> On Jul 29, 2016, at 2:02 AM, Denis Kudriashov <dionisiydk at gmail.com> wrote:
> 
> Hi.
> 
> I compared performance between object instantiation and object cloning. I was wondering that instantiation almost twice faster than clone (primitive 70 vs 148).
> 
> Could you explain why it like that and could it be improved?
> 
> I was think that new object construction is much complex because it requires to fill all object fields (header structure and etc).
> And I was think that copy is just simple function like memcpy which just copy bytes without any logic.
> 
> Here is my code:
> 
> object := Object new.
> 3 timesRepeat: [ Smalltalk garbageCollect ].
> result1 := [ Object basicNew ] benchFor: 10 seconds.
> 3 timesRepeat: [ Smalltalk garbageCollect ].
> result2 := [ object shallowCopy ] benchFor: 10 seconds.
> {result1. result2}.
>  "an Array(a BenchmarkResult(518,021,045 iterations in 10 seconds 2 milliseconds. 51,791,746 per second) a BenchmarkResult(302,807,253 iterations in 10 seconds 4 milliseconds. 30,268,618 per second))" 
> 
> (I run it on latest Pharo on Mac SpurVM)
> 
> Best regards,
> Denis


More information about the Vm-dev mailing list