 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Eric Grange Guest
|
Posted: Wed Oct 05, 2005 10:53 am Post subject: Object Creation/Destruction (was ObjPool) |
|
|
Posted a hacked up version of Gabriel's ObjPool, and a mini-bench.
This is still to investigate feasability more than anything else...
Mostly simplification to focus on getting NewInstance right and fast:
- pools removed (yeah...), only pooling is now FastMM's
- FreeInstance redirection removed
- NewInstance redirect simplified
- uses 'original' NewInstance implem to get a template object
- replaced object pool list with chained list (for memory overhead)
On creating/destroying TInterfacedObject, execution time is almost
halved (and there is currently NO speedup on the destruction side),
for TObject, it's 30%, for TStringList, it's 20%.
Issues and things to check/improve/figure out:
- should work even with NewInstance implems that invoke their inherited,
but this hasn't been tested, won't work with NewInstance hacks that
setup instance-specific fields in NewInstance rather than constructor
- template is fully copied in the new NewInstance, ideally, we could
copy only the object header and fill the rest with zeroes, for objects
with many/large fields, zeroes are bound to outnumber header data
- copy uses rep movsd
Next objectives:
- removing AddClassPool and making it automagic
- testing in large-scale real-world situations
- tackling FreeInstance speedups (how to? possible? worth it?)
- getting pooling back in (worth it?)
Eric
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Wed Oct 05, 2005 1:16 pm Post subject: Re: Object Creation/Destruction (was ObjPool) |
|
|
Is there a way for a module to enumerate all its
classes VMTs at runtime?
Eric
|
|
| Back to top |
|
 |
Pierre le Riche Guest
|
Posted: Wed Oct 05, 2005 3:33 pm Post subject: Re: Object Creation/Destruction (was ObjPool) |
|
|
Hi Eric,
| Quote: | This is still to investigate feasability more than anything else...
|
I have modified InitInstance in my D7 RTL to be a little bit faster. I think
part of the problem is the use of "rep stos" in the default handler. Would
be interested to see how this compares to the object pool with classes that
doesn't have any interfaces (which represents most of the performance
critical classes in my experience).
Regards,
Pierre
Code below:
class function TObject.InitInstance(Instance: Pointer): TObject;
asm
PUSH EBX
PUSH ESI
PUSH EDI
MOV EBX,EAX
//start of modified code
{Get the instance size in ecx}
mov ecx, [eax].vmtInstanceSize
{Point edi to the last dword}
lea edi, [edx + ecx - 4]
{Clear eax}
xor eax, eax
{Clear the last DWord}
mov [edi], eax
{Store the class pointer (first DWord)}
mov [edx], ebx
{Subtract the 8 bytes already stored. Is the instance size 8 or less? If
so,
we're done}
sub ecx, 8
jle @ClearDone
{Negate the counter}
neg ecx
{Is it worthwhile using MMX to clear the memory?}
add ecx, 32
jns @ClearDWords
movd mm0, eax
@Clear32Loop:
movq [edi + ecx - 32], mm0
movq [edi + ecx - 24], mm0
movq [edi + ecx - 16], mm0
movq [edi + ecx - 8], mm0
add ecx, 32
js @Clear32Loop
{Exit mmx state}
emms
@ClearDWords:
sub ecx, 32
@ClearDWordLoop:
mov [edi + ecx], eax
add ecx, 4
js @ClearDWordLoop
@ClearDone:
//end of modified code
MOV EAX,EDX
MOV EDX,ESP
@@0: MOV ECX,[EBX].vmtIntfTable
TEST ECX,ECX
JE @@1
PUSH ECX
@@1: MOV EBX,[EBX].vmtParent
TEST EBX,EBX
JE @@2
MOV EBX,[EBX]
JMP @@0
@@2: CMP ESP,EDX
JE @@5
@@3: POP EBX
MOV ECX,[EBX].TInterfaceTable.EntryCount
ADD EBX,4
@@4: MOV ESI,[EBX].TInterfaceEntry.VTable
TEST ESI,ESI
JE @@4a
MOV EDI,[EBX].TInterfaceEntry.IOffset
MOV [EAX+EDI],ESI
@@4a: ADD EBX,TYPE TInterfaceEntry
DEC ECX
JNE @@4
CMP ESP,EDX
JNE @@3
@@5: POP EDI
POP ESI
POP EBX
end;
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Wed Oct 05, 2005 3:50 pm Post subject: Re: Object Creation/Destruction (was ObjPool) |
|
|
Updated in the attachments NG.
New version automagically registers all classes.
Should be thread-safe.
Just drop the unit in your uses after FastMM4... observe...
....and report :)
Just knowing large applications survive the unit would be good news.
Speedups aren't expected to be visible unless you create a whole lot of
objects with reasonnably simple constructors or objects that expose
a lot of interfaces.
Eric
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Wed Oct 05, 2005 4:01 pm Post subject: Re: Object Creation/Destruction (was ObjPool) |
|
|
Posted the unit, so you should be able to compare and also
adapt the RAZ loop to MMX - posted implem only has the 32bit
trivial clear loop... I'm still having trouble grasping those
neg ecx/jns/js fast loops -
Let me now how/if VMT init stuff removal matters.
Eric
|
|
| Back to top |
|
 |
Daniel Rikowski Guest
|
Posted: Wed Oct 05, 2005 5:05 pm Post subject: Re: Object Creation/Destruction (was ObjPool) |
|
|
Hello Eric,
| Quote: | Just drop the unit in your uses after FastMM4... observe...
...and report
|
OK :)
| Quote: | Just knowing large applications survive the unit would be good news.
|
I've just tested your unit and my application still works perfectly.
However, FastMM reports many many memory leaks at shutdown.
The application is multithreaded and makes extensive use of interfaced
objects, both Delphi and COM objects.
Regards,
Daniel
|
|
| Back to top |
|
 |
Nathanial Woolls Guest
|
Posted: Wed Oct 05, 2005 6:12 pm Post subject: Re: Object Creation/Destruction (was ObjPool) |
|
|
On Wed, 05 Oct 2005 11:50:42 -0400, Eric Grange
<egrangeNO (AT) SPAMglscene (DOT) org> wrote:
| Quote: | Just drop the unit in your uses after FastMM4... observe...
...and report
|
No errors but lots of leaks reported by FastMM4.
|
|
| Back to top |
|
 |
Darryl Strickland Guest
|
Posted: Wed Oct 05, 2005 8:59 pm Post subject: Re: Object Creation/Destruction (was ObjPool) |
|
|
This program creates 100's to 1000's of TObject descendants and destorys
them every second. I did notice about a 30% speed increase but so many
leaks reported by FastMM more than filled my screen. Excellent start with
the speed!
Darryl
Nathanial Woolls wrote:
| Quote: | On Wed, 05 Oct 2005 11:50:42 -0400, Eric Grange
[email]egrangeNO (AT) SPAMglscene (DOT) org[/email]> wrote:
Just drop the unit in your uses after FastMM4... observe...
...and report :)
No errors but lots of leaks reported by FastMM4.
|
|
|
| Back to top |
|
 |
Gabriel Corneanu Guest
|
Posted: Thu Oct 06, 2005 5:03 am Post subject: Re: Object Creation/Destruction (was ObjPool) |
|
|
I already solved, the memory leaks, coming soon.
Gabriel
"Darryl Strickland" <dstrickland (AT) carolina (DOT) rr.com> wrote
| Quote: | This program creates 100's to 1000's of TObject descendants and destorys
them every second. I did notice about a 30% speed increase but so many
leaks reported by FastMM more than filled my screen. Excellent start with
the speed!
Darryl
Nathanial Woolls wrote:
On Wed, 05 Oct 2005 11:50:42 -0400, Eric Grange
[email]egrangeNO (AT) SPAMglscene (DOT) org[/email]> wrote:
Just drop the unit in your uses after FastMM4... observe...
...and report :)
No errors but lots of leaks reported by FastMM4.
|
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Thu Oct 06, 2005 7:43 am Post subject: Re: Object Creation/Destruction (was ObjPool) |
|
|
| Quote: | No errors but lots of leaks reported by FastMM4.
|
Thanks all for reporting :)
If those lots of leaks are 1 of each class, then the fix is
to add the missing:
FastFreeMem(FTemplate);
after CleanupInstance in TClassPool.CleanupTemplate.
If it's more than 1 leak of each class, then more bug hinting will
be required...
Eric
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|