[fpc-pascal] for loops performance problems?

Anthony Walter sysrpl at gmail.com
Tue Jul 4 11:09:34 CEST 2017


I recall earlier this year some people in this mailing list were discussing
surprising performance problems with fpc and for loops. I wanted to know if
this is still an existing problem as I am experiencing some unusual
performance degradation related to a for loop in one of my test
applications.

Here is a description of my test application:

http://cache.getlazarus.org/videos/fonts.mp4 (vsync on for recording
purposes)

An opengl window which renders example text of various fonts. The user can
press a key to cycle through the available fonts to see how they look as
textured billboard sprites. The text displays in a few paragraphs.

The performance issue:

Adding a paragraph of sample text greatly reduces the opengl frame rate. On
some systems, like the raspberry pi, the frame rate can drop to 10 frames a
second. This seems like a bit much of a low frame rate given that it's
actually not a lot of geometry (4 vert or colors per character).

When I turn on geometry buffering, that is storing the vertex information,
then drawing using a user memory vertex buffer, the frame rate skyrockets
to 200+ fps (vsync is off) on a raspberry.

I think the code to generate the geometry each frame isn't that complex,
and I pre-allocate room in my buffer for all the geometry just once, so it
seems doing to calculations for the geometry is what's killing the
performance. The calculations are simple multiplication of "Single" type,
and I am thinking maybe the "for looping" part is what's degrading
performance.

Here is the gist of the loop that generates the text vertex buffer:

https://gist.github.com/sysrpl/8af6e5a9d62cc2f2a1c40f9a9ae13b64

I can convert to static buffers and get good performance (if I know the
text isn't changing), but I'm now curious if this specific performance
issue is related to fpc's for loop code generation.

What do you think?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170704/37cfd036/attachment.html>


More information about the fpc-pascal mailing list