GC finalizer optimization.
Dave
Dave_member at pathlink.com
Tue Apr 11 15:21:11 PDT 2006
Argh - I forgot about needing to release synchronization resources or
zeroing the vptr. regardless of if there is a dtor or not...
Damn.
Dave wrote:
>
> Comments? Like, how can this break things?
>
> By changing line 129 of phobos/internal/gc/gc.d from:
>
> _gc.setFinalizer(p, &new_finalizer);
>
> to:
>
> ///_gc.setFinalizer(p, &new_finalizer);
> ///
> ClassInfo c = ci;
> do
> {
> if (c.destructor)
> {
> _gc.setFinalizer(p, &new_finalizer);
> }
> c = c.base;
> } while (c);
> ///
>
> gives me about 3x performance in allocating class objects w/o a dtor
> using the following code.
>
> Before:
> D::~this
> C::~this
> C::~this
> 0.829
>
> After:
> D::~this
> C::~this
> C::~this
> 0.258
>
> ;---
>
> import std.date, std.stdio;
>
> void main()
> {
> C c = new C;
> D d = new D;
> E e;
> F f;
>
> d_time st = getUTCtime();
> for(int i = 0; i < 1_000_000; i++)
> {
> e = new E;
> f = new F;
> }
> d_time et = getUTCtime();
> writefln((et - st) / cast(double)TicksPerSecond);
> }
>
> class C
> {
> int i;
> ~this()
> {
> printf("C::~this\n");
> }
> }
>
> class D : C
> {
> int i;
> ~this()
> {
> printf("D::~this\n");
> }
> }
>
> class E
> {
> int i;
> }
>
> class F : E
> {
> int i;
> }
>
> Thanks,
>
> - Dave
More information about the Digitalmars-d
mailing list