JIT compilation for System.Initialize() – Part 2

By | December 21, 2008

The usage of the JITtered System.Initialize in real world applications (RAD Studio 2009 and some of my own projects) showed me that the performance increase isn’t measurable. This has to do with the fact that records aren’t widely used. And if they are used they are relative simple records with less than 3 managed types. The JITter can only play out his cards if there are many managed types in a record like in this:

  TTest = record
    Rec1: array[0..1] of record
      Str: string;
      Intf: IInterface;
      Rec: record
        Str: array[0..63] of string;
        Intf: IInterface;
      end;
      I: Integer;
    end;
    Rec2: record
      Str: string;
    end;
    I1: Integer;
    S: string;
    I2: Integer;
    Intf: IInterface;
    A: array of Byte;
  end;
 
var
  m: array[0..1024] of TTest;

Original RTTI version (called 10000 times)
=> 2844,406998 ms

JITtered version (called 10000 times)
=> 477,229718 ms

But such records are rare.

It was a nice research project with lot’s of interesting parts (record analyses via RTTI, optimizing the JITter raw data, generating machine code) but the outcome didn’t gave the expected results.

4 thoughts on “JIT compilation for System.Initialize() – Part 2

  1. Eric

    Personally, I wouldn’t be using a better Initialize for records as complex as this one (whoever would use such a complex record would probably have lots of other bottlenecks in his code), but for small simple records, holding a single string, a single interface, and rarely more than a handful.

  2. Denis

    You didn’t get the expected results but you got something interesting: a base for a JIT in Delphi.
    Will you share the source code of your experiments?

  3. Andreas Hausladen Post author

    I don’t think that the JIT Compiler that I’ve written for this project can be used for anything else than for the Initialize function. It only supports 8 different machine code instructions and uses a specialized intermediate language that can only describe the InitializeRecord/FinalizeRecord/CopyRecord code. Especially the data structure of this IL is tied to the PTypeInfo record.

    mov [eax+ofs],edx
    add eax,ofs
    mov ecx, count
    dec ecx
    jnz
    push ecx
    pop ecx
    ret

Comments are closed.