[fpc-devel] Class field reordering

Sven Barth pascaldragon at googlemail.com
Mon Jul 16 13:14:47 CEST 2012

Am 14.07.2012 01:45 schrieb "Jonas Maebe" <jonas.maebe at elis.ugent.be>:
> Hi,
> I've implemented an optimization that reorders the instance fields of
Delphi-style classes (and only of Delphi-style classes) to minimise memory
gaps caused by alignment differences and odd sizes. The effect is the same
as when you would change the order of the fields in the source code to
achieve this effect.
> In general, I think this should be safe since unlike records and TP-style
objects, a Delphi class is normally never blockwritten to disk or so. There
is a switch to disable this transformation, but I'm wondering whether
anyone sees a problem with enabling it by default when -O2 or higher is
> It works fine with at least the compiler and Lazarus without any ill
effects, saving a small amount of memory for both (about 2.5MB on 87MB for
the Darwin/x86-64 compiler compiling itslf, and 2.5MB on 62.7MB for a
Carbon/i386 Lazarus right after startup and loading some source files).
> Jonas
> PS: a similar reordering could be performed for local variables, although
the implementation would be quite different. Additionally, different kinds
of reordering, e.g. targeting cache improvements by putting fields/local
variables often used together next to each other, could also be implemented
in the future.

While reading Skybuck's second mail I got a thought: does this optimization
also apply on systems that require proper alignment for memory accesses?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20120716/307b1dd3/attachment.html>

More information about the fpc-devel mailing list