Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2020-11

Compilation speed on Apple M1

22 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Tobias Giesen

Hello,

first and foremost, many thanks to the creators and contributors of FPC and Lazarus, who enabled me to release my product natively for Apple Silicon only one day after receiving an M1 Mac. Fantastic work! FPC and Lazarus both run natively and work very well.

According to Geekbench, the single core performance on the new Mac is around 1.8x as fast as my Intel Mac. Multicore is also much faster. I wonder why I don't see the speed increase in compiling though. Yes I am using different FPC and XCode versions, but I wonder what else could have an influence? My project is very large and not divided into packages, so I frequently need to recompile the whole project.

I would be most grateful for any performance tips.

Cheers,
Tobias

Reply by email

Jonas Maebe
to Tobias Giesen
Tobias Giesen wrote
According to Geekbench, the single core performance on the new Mac is around 1.8x as fast as my Intel Mac.

Geekbench scores cannot be compared across different architectures.

I wonder why I don't see the speed increase in compiling though.

The fact that you get similar speed on a cpu that probably uses quite a bit less than half the power of your previous one is quite impressive.

Jonas

Reply by email

Florian Klämpfl
to Tobias Giesen: first and foremost, many thanks to the creators and contributors of FPC and Lazarus, who…
Tobias Giesen wrote 7 lines
According to Geekbench, the single core performance on the new Mac is around 1.8x as fast as my Intel Mac. Multicore is also much faster. I wonder why I don't see the speed increase in compiling though. Yes I am using different FPC and XCode versions, but I wonder what else could have an influence? My project is very large and not divided into packages, so I frequently need to recompile the whole project.

Large parts of FPC are memory throughput limited so I suspect the M1 is not that much better in this regard, not to mention that most likely the AAarch code generator is worse than the x86 one. x86 received a lot of work in this field.

Maybe it's possible that you build using an LLVM compiler the FPC with native backend. As I do not use macOS, I have no clue how to do this though.

Reply by email

Tobias Giesen
to Florian Klämpfl

Hi,
many thanks for the replies! I actually think most of the time is used by clang for assembling. If I can find out more precise details, I will let you know. And it is already a little bit faster on M1 than on my Intel.

Kind Regards,

Tobias Giesen
Super Flexible Software GmbH & Co. KG

----

Show quoted text 17 lines
Am 21.11.2020 um 12:54 schrieb Tobias Giesen via fpc-pascal: > > According to Geekbench, the single core performance on the new Mac is > around 1.8x as fast as my Intel Mac. Multicore is also much faster. I > wonder why I don't see the speed increase in compiling though. Yes I am > using different FPC and XCode versions, but I wonder what else could > have an influence? My project is very large and not divided into > packages, so I frequently need to recompile the whole project. Large parts of FPC are memory throughput limited so I suspect the M1 is not that much better in this regard, not to mention that most likely the AAarch code generator is worse than the x86 one. x86 received a lot of work in this field. Maybe it's possible that you build using an LLVM compiler the FPC with native backend. As I do not use macOS, I have no clue how to do this though. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Kind Regards,
Tobias Giesen

Super Flexible Software GmbH & Co. KG
Buddenstr. 29-31
48143 Münster, Germany
www.superflexible.com
www.tgtools.com

----------------------------------------------------------- Registered at register court Münster as HRA 9716
Liability / general partner: TGTools GmbH
Registered at register court Münster as HRB 17763 Directors: Tobias Giesen and Claudia Giesen

Reply by email

Marco van de Voort
to Florian Klämpfl: Large parts of FPC are memory throughput limited so I suspect the M1 is not that much…

Op 2020-11-21 om 14:15 schreef Florian Klämpfl via fpc-pascal:

Show quoted text 14 lines
Am 21.11.2020 um 12:54 schrieb Tobias Giesen via fpc-pascal: > > According to Geekbench, the single core performance on the new Mac is > around 1.8x as fast as my Intel Mac. Multicore is also much faster. I > wonder why I don't see the speed increase in compiling though. Yes I am > using different FPC and XCode versions, but I wonder what else could > have an influence? My project is very large and not divided into > packages, so I frequently need to recompile the whole project. Large parts of FPC are memory throughput limited so I suspect the M1 is not that much better in this regard, not to mention that most likely the AAarch code generator is worse than the x86 one. x86 received a lot of work in this field.

Some memory throughput details are here:
https://www.anandtech.com/show/16252/mac-mini-apple-m1-tested

M1 is listed as 96ns memory latency through a 128-bit bus.

A Zen3 (ryzen 5x00) should be 67-83ns depending on type of memory:

https://www.anandtech.com/show/14605/the-and-ryzen-3700x-3900x-review-raising-the-bar/2

which in dual channel mode afaik is also 128-bit.

Maybe it's possible that you build using an LLVM compiler the FPC with native backend. As I do not use macOS, I have no clue how to do this though.

Do the x86(_64) OSX(I) FPC compilers use binary object writers?

Reply by email

Ryan Joseph
to Florian Klämpfl: Large parts of FPC are memory throughput limited so I suspect the M1 is not that much…
On Nov 21, 2020, at 6:15 AM, Florian Klämpfl via fpc-pascal wrote: Large parts of FPC are memory throughput limited so I suspect the M1 is not that much better in this regard, not to mention that most likely the AAarch code generator is worse than the x86 one. x86 received a lot of work in this field.

What does that mean exactly to be "memory throughput limited"? What part of the compilation process does this affect exactly?

Regards,
Ryan Joseph

Reply by email

Jonas Maebe
to Florian Klämpfl: Large parts of FPC are memory throughput limited so I suspect the M1 is not that much…
Florian Klämpfl wrote 17 lines
Am 21.11.2020 um 12:54 schrieb Tobias Giesen via fpc-pascal: > > According to Geekbench, the single core performance on the new Mac is > around 1.8x as fast as my Intel Mac. Multicore is also much faster. I > wonder why I don't see the speed increase in compiling though. Yes I am > using different FPC and XCode versions, but I wonder what else could > have an influence? My project is very large and not divided into > packages, so I frequently need to recompile the whole project. Large parts of FPC are memory throughput limited so I suspect the M1 is not that much better in this regard, not to mention that most likely the AAarch code generator is worse than the x86 one. x86 received a lot of work in this field. Maybe it's possible that you build using an LLVM compiler the FPC with native backend. As I do not use macOS, I have no clue how to do this though.

For compiling the compiler itself, excluding assembling and linking, a compiler compiled using the LLVM backend (but that generates code using our native code generator (*) ) is 18.85% faster than one compiled using our native code generator (on a Developer Transition Kit, but I guess it will be similar on the M1).

If you include assembling and linking (which you obviously always have to do), the speed difference shrinks to 8.5%. So more time is spent in the assembler (clang) and ld than in the compiler.

As to how to do build a compiler on macOS that uses the LLVM backend, that's the same as on Linux, except that you don't need special command line options to find libgcc: https://wiki.freepascal.org/LLVM

Jonas

(*) using the LLVM backend is slower because clang's code generator is
much slower than FPC's.

Reply by email

Ryan Joseph
to Jonas Maebe
Show quoted text 5 lines
On Nov 21, 2020, at 9:18 AM, Jonas Maebe via fpc-pascal wrote: As to how to do build a compiler on macOS that uses the LLVM backend, that's the same as on Linux, except that you don't need special command line options to find libgcc: https://wiki.freepascal.org/LLVM

It sounds like the LLVM backend is superior so is it the plan to start distributing compiler releases built from LLVM? What are the plans for the native code generator if it's being outperformed by the LLVM backend?

Regards,
Ryan Joseph

Reply by email

Florian Klämpfl
to Ryan Joseph: What does that mean exactly to be "memory throughput limited"? What part of the…
Ryan Joseph wrote 8 lines
> On Nov 21, 2020, at 6:15 AM, Florian Klämpfl via fpc-pascal wrote: > > Large parts of FPC are memory throughput limited so I suspect the M1 is not that much better in this regard, not to mention that most likely the AAarch code generator is worse than the x86 one. x86 received a lot of work in this field. What does that mean exactly to be "memory throughput limited"? What part of the compilation process does this affect exactly?

All. FPC typically uses several ten MBs and accesses it rather randomly.

Reply by email

Ryan Joseph
to Florian Klämpfl: All. FPC typically uses several ten MBs and accesses it rather randomly.
On Nov 21, 2020, at 9:23 AM, Florian Klämpfl via fpc-pascal wrote: All. FPC typically uses several ten MBs and accesses it rather randomly.

Wow 10-100 MB is enough to limit speed due to memory access times? I understand there is some limit to how much memory can be accessed per X period of time but I thought it was measured in GB before getting penalties. Shows what I know. :)

I don't see the compiler changing in architecture however so we'll just wait for faster hardware. ;)

Regards,
Ryan Joseph

Reply by email

Florian Klämpfl
to Ryan Joseph
Ryan Joseph wrote 7 lines
> On Nov 21, 2020, at 9:23 AM, Florian Klämpfl via fpc-pascal wrote: > > All. FPC typically uses several ten MBs and accesses it rather randomly. Wow 10-100 MB is enough to limit speed due to memory access times? I understand there is some limit to how much memory can be accessed per X period of time but I thought it was measured in GB before getting penalties. Shows what I know. :)

L1 cache is typically only a few ten kB, L2 several hundred kB, L3 several MB.

Reply by email

Ryan Joseph
to Florian Klämpfl
On Nov 21, 2020, at 9:33 AM, Florian Klämpfl via fpc-pascal wrote: L1 cache is typically only a few ten kB, L2 several hundred kB, L3 several MB.

Oh I see what you mean. Yeah cache miss is a problem that would be not feasible to fix in the compiler for the most part.

I guess this means FPC has reached more or less maximum speeds until memory access speeds are improved in the hardware.

Regards,
Ryan Joseph

Reply by email

Florian Klämpfl
to Tobias Giesen: first and foremost, many thanks to the creators and contributors of FPC and Lazarus, who…
Tobias Giesen wrote 15 lines
Hello, first and foremost, many thanks to the creators and contributors of FPC and Lazarus, who enabled me to release my product natively for Apple Silicon only one day after receiving an M1 Mac. Fantastic work! FPC and Lazarus both run natively and work very well. According to Geekbench, the single core performance on the new Mac is around 1.8x as fast as my Intel Mac. Multicore is also much faster. I wonder why I don't see the speed increase in compiling though. Yes I am using different FPC and XCode versions, but I wonder what else could have an influence? My project is very large and not divided into packages, so I frequently need to recompile the whole project. I would be most grateful for any performance tips.

In r47526, I implemented support of the prefetch intrinsic on aarch64. On my Raspi4 it reduced make cycle time by 25 % (!). I would be very interested to get numbers for the M1.

Reply by email

Michael Van Canneyt
to Florian Klämpfl
Florian Klämpfl wrote 20 lines
Am 21.11.2020 um 12:54 schrieb Tobias Giesen via fpc-pascal: > Hello, > > first and foremost, many thanks to the creators and contributors of FPC > and Lazarus, who enabled me to release my product natively for Apple > Silicon only one day after receiving an M1 Mac. Fantastic work! FPC and > Lazarus both run natively and work very well. > > According to Geekbench, the single core performance on the new Mac is > around 1.8x as fast as my Intel Mac. Multicore is also much faster. I > wonder why I don't see the speed increase in compiling though. Yes I am > using different FPC and XCode versions, but I wonder what else could > have an influence? My project is very large and not divided into > packages, so I frequently need to recompile the whole project. > > I would be most grateful for any performance tips. In r47526, I implemented support of the prefetch intrinsic on aarch64. On my Raspi4 it reduced make cycle time by 25 % (!). I would be very interested to get numbers for the M1.

25% ?!

Well...
If the compiler can make such a difference, should we still bother with micro-optimizations in code then ?

Michael.

Reply by email

Florian Klämpfl
to Michael Van Canneyt
Show quoted text 23 lines
Am 22.11.2020 um 11:45 schrieb Michael Van Canneyt via fpc-pascal :  > On Sun, 22 Nov 2020, Florian Klämpfl via fpc-pascal wrote: > >> Am 21.11.2020 um 12:54 schrieb Tobias Giesen via fpc-pascal: >> Hello, >> first and foremost, many thanks to the creators and contributors of FPC >> and Lazarus, who enabled me to release my product natively for Apple >> Silicon only one day after receiving an M1 Mac. Fantastic work! FPC and >> Lazarus both run natively and work very well. >> According to Geekbench, the single core performance on the new Mac is >> around 1.8x as fast as my Intel Mac. Multicore is also much faster. I >> wonder why I don't see the speed increase in compiling though. Yes I am >> using different FPC and XCode versions, but I wonder what else could >> have an influence? My project is very large and not divided into >> packages, so I frequently need to recompile the whole project. >> I would be most grateful for any performance tips. > > In r47526, I implemented support of the prefetch intrinsic on aarch64. On my Raspi4 it reduced make cycle time by 25 % (!). I would be very interested to get numbers for the M1. 25% ?!

Yes. I were also baffled and tested several times but numbers didn‘t change. This is why I would like to see numbers from others.

Well... If the compiler can make such a difference,

This are the big low hanging fruits, their are only a few :) In particular the compiler benefits a lot from this as it iterates linked lists a lot.

should we still bother with micro-optimizations in code then ?

I am always against micro-optimising code, this should do the compiler though prefetch is also a matter of inserting the intrinsic in your code. FPC can do this automatically but so far it is disabled as it is overall not beneficial.

Michael._______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Tobias Giesen
to Florian Klämpfl: In r47526, I implemented support of the prefetch intrinsic on aarch64. On my Raspi4 it…

Hello Florian,
many thanks for this!

To compare performance, is it sufficient to add the FTP=xxx parameter and point it to the different ppca64 versions?

And should I compile the older source snapshort with the older version, and today's snapshot with the newer ppca64?

I just want to do the test correctly.

Cheers,
Tobias

----

In r47526, I implemented support of the prefetch intrinsic on aarch64. On my Raspi4 it reduced make cycle time by 25 % (!). I would be very interested to get numbers for the M1.

Reply by email

Ryan Joseph
to Florian Klämpfl: Yes. I were also baffled and tested several times but numbers didn‘t change. This is…
Show quoted text 5 lines
On Nov 22, 2020, at 4:08 AM, Florian Klämpfl via fpc-pascal wrote: > Well... If the compiler can make such a difference, This are the big low hanging fruits, their are only a few :) In particular the compiler benefits a lot from this as it iterates linked lists a lot.

Just curious, how does the "prefetch intrinsic" help with iterating linked lists?

Regards,
Ryan Joseph

Reply by email

Liam Proven
to Florian Klämpfl: L1 cache is typically only a few ten kB, L2 several hundred kB, L3 several MB.
Florian Klämpfl wrote
L1 cache is typically only a few ten kB, L2 several hundred kB, L3 several MB.

Some real-world comparisons in human units:

https://gist.github.com/hellerbarde/2843375

https://www.pcgamer.com/heres-a-neat-trick-for-understanding-how-long-computer-processes-take/

If fetching the next instruction from the next location in L1 cache took 1 second, getting it from main memory would take over a minute and a half. Getting it from an SSD, a weekend. Getting it from a hard disk, about 4 months.

Liam Proven – Profile: https://about.me/liamproven Email: – gMail/gTalk/gHangouts: Twitter/Facebook/LinkedIn/Flickr: lproven – Skype: liamproven UK: +44 7939-087884 – ČR (+ WhatsApp/Telegram/Signal): +420 702 829 053

Reply by email

Jonas Maebe
to Ryan Joseph: Just curious, how does the "prefetch intrinsic" help with iterating linked lists? Ryan…
Ryan Joseph wrote 5 lines
> On Nov 22, 2020, at 4:08 AM, Florian Klämpfl via fpc-pascal wrote: > >> Well... If the compiler can make such a difference, > This are the big low hanging fruits, their are only a few :) In particular the compiler benefits a lot from this as it iterates linked lists a lot. Just curious, how does the "prefetch intrinsic" help with iterating linked lists?

By prefetching the next element in the background while processing the current element. Since the elements are not necessarily placed behind each other in memory, the processor's built-in prefetcher can't handle this.

Jonas

Reply by email