Object>>#pinInMemory performance

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Object>>#pinInMemory performance

Aliaksei Syrel
Hello

I stumbled across a performance issue when pinning objects in memory.
Below I have two scripts that pin and unpin a byte array (or any object) 20k times.

The first script pins each time a new byte array: 
[ 20000 timesRepeat:  [
  | array wasPinned |
  array := ByteArray new.
  wasPinned := array pinInMemory.
  array setPinnedInMemory: wasPinned.
] ] timeToRunWithoutGC. "4284"

while the second one pins the same instance of array:
array := ByteArray new.
[ 20000 timesRepeat:  [
   | wasPinned |
   wasPinned := array pinInMemory.
   array setPinnedInMemory: wasPinned.
] ] timeToRunWithoutGC "12"

However, as you can see there is a huge performance difference between these scripts.

Is it expected or is it a bug? And if it is expected what can be happening in VM that leads to such huge performance impact? Thanks!

Cheers,
Alex