Oberon Community Platform Forum
December 12, 2019, 09:18:16 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Strange behaviour of Heaps  (Read 7781 times)
Alexey
Newbie
*
Posts: 27


« on: January 09, 2009, 03:21:49 PM »

Hello A2 developers,

this is a small procedure to reproduce the problem:

PROCEDURE Test*;
VAR
   t: Kernel.MilliTimer;
   time: LONGINT;
   X, Y, Z: POINTER TO ARRAY OF LONGREAL;
BEGIN
      
   Kernel.SetTimer(t,0);
   NEW(X,4);
   time := Kernel.Elapsed(t);
   
   Log.String('Allocation of X: '); Log.Int(time,0); Log.Ln;
      
   Kernel.SetTimer(t,0);
   NEW(Y,4096*4096);
   time := Kernel.Elapsed(t);
      
   KernelLog.String('Allocation of Y: '); KernelLog.Int(time,0); KernelLog.Ln;
      
   Kernel.SetTimer(t,0);
   NEW(Z,4);
   time := Kernel.Elapsed(t);
      
   KernelLog.String('Allocation of Z: '); KernelLog.Int(time,0); KernelLog.Ln;
   
   KernelLog.String('Done!'); KernelLog.Ln;
END Test;

and this is the output for 3 retries using the latest WinAos release:

Allocation of X: 0
Allocation of Y: 109
Allocation of Z: 265
Done!


Allocation of X: 0
Allocation of Y: 78
Allocation of Z: 297
Done!


Allocation of X: 0
Allocation of Y: 78
Allocation of Z: 281
Done!

A conclusion: after allocation of a large array which took time t1 allocation of a very small array takes 2-3 times more than t1!!!
This is an extreme performance killer.

Best regards,

Alexey

Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #1 on: January 09, 2009, 03:38:10 PM »

I can not reproduce your results
   
the example little understood (present a module Log and KernelLog)

My results:
Quote
Allocation of X: 0
Allocation of Y: 594
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 3609
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 531
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 562
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 547
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 531
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 546
Allocation of Z: 0
Done!

Code:
MODULE Test;
IMPORT Kernel,Log:=KernelLog;
PROCEDURE Test*;
VAR
   t: Kernel.MilliTimer;
   time: LONGINT;
   X, Y, Z: POINTER TO ARRAY OF LONGREAL;
BEGIN
     
   Kernel.SetTimer(t,0);
   NEW(X,4);
   time := Kernel.Elapsed(t);
   
   Log.String('Allocation of X: '); Log.Int(time,0); Log.Ln;
     
   Kernel.SetTimer(t,0);
   NEW(Y,4096*4096);
   time := Kernel.Elapsed(t);
     
   Log.String('Allocation of Y: '); Log.Int(time,0); Log.Ln;
     
   Kernel.SetTimer(t,0);
   NEW(Z,4);
   time := Kernel.Elapsed(t);
     
   Log.String('Allocation of Z: '); Log.Int(time,0); Log.Ln;
   
   Log.String('Done!'); Log.Ln;
END Test;
END Test.Test~
Logged
sage
Full Member
***
Posts: 170



WWW
« Reply #2 on: January 09, 2009, 03:47:49 PM »

The question is: are results obtained on WinAos or A2?
In my case (WinAos), sometimes it takes place but results rather differs:
Quote
Allocation of X: 0
Allocation of Y: 94
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 109
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 110
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 109
Allocation of Z: 31
Done!
Allocation of X: 0
Allocation of Y: 94
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 109
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 109
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 110
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 94
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 94
Allocation of Z: 47
Done!
Allocation of X: 0
Allocation of Y: 109
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 94
Allocation of Z: 0
Done!
Allocation of X: 0
Allocation of Y: 109
Allocation of Z: 47
Done!
Logged
Alexey
Newbie
*
Posts: 27


« Reply #3 on: January 09, 2009, 05:58:08 PM »

As I wrote before "using the latest WinAos release".

A comment: the test was originally done on Windows Vista. I run it on the same machine (Quad Core Q9400, 4000Mb DDR2) with WinXP SP3,- the same slowness was observed quite rarely, but anyway it happened.

Can anybody run the test directly on A2?

Regards,

Alexey
Logged
soren renner
Global Moderator
Full Member
*****
Posts: 216



« Reply #4 on: January 09, 2009, 08:10:45 PM »

On A2 latest release running on core duo, clockrate estimated 2592 mhz, MMX SSE SSE2 capable:

Allocation of X: 0
Allocation of Y: 2
Allocation of Z: 0

Allocation of X: 0
Allocation of Y: 2
Allocation of Z: 0

Allocation of X: 0
Allocation of Y: 2
Allocation of Z: 0

....
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #5 on: January 09, 2009, 09:07:11 PM »

Striking contrast
WinAos
Allocation of Y: 109
Native:
Allocation of Y: 2

 Grin
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #6 on: January 09, 2009, 11:14:24 PM »

Is this delay caused by the garbage collector? I've just seen that Win32.Machine.SetGCParams sets the GCThreshold to 10MB (this means that after allocating 10MB, a memory allocation will trigger the GC).
You can inspect Heaps.Ngc to see how often the GC runs.

Also, Win32.Machine.ExpandHeap is a good candidate for such delays... if I see this correctly, the heap is expanded in very small steps...

Update: Ok, the delay for allocation Z is definitely the GC (since 16 * 8 MB is allocated). The allocation of Y is most likely caused by the attempt of WinAos to release memory as soon as possible (Heaps.NewBlock does not involve Windows if WinAos has enough heap and should be as fast as A2, but if you have to ask Windows for memory...)
« Last Edit: January 10, 2009, 01:46:23 AM by staubesv » Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #7 on: January 10, 2009, 01:39:56 AM »

I've made some experiments... The attached modified files allow the specification of GCThreshold and minimum heap size in aos.ini. As expected, the allocation for Z is much better (most often below 1ms) when setting a very high GC threshold. The allocation of Y is still quite slow (approx. 60ms on my machine).

I you want to experiment:
- Interface of modules remained the same (no need to recompile other modules)
- in aos.ini: (sizes in MB)
MinHeapSize = 512
GCThreshold = 256

* Heaps.Mod (72.43 KB - downloaded 399 times.)
* Win32.Machine.Mod (32.78 KB - downloaded 372 times.)
« Last Edit: January 10, 2009, 01:45:58 AM by staubesv » Logged
Alexey
Newbie
*
Posts: 27


« Reply #8 on: January 12, 2009, 10:35:34 AM »

Thank you Sven!

It is better with your experimental changes Smiley

Regards,

Alexey
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!