How important is it to group same operations together?

Hi there!

I am currently implementing a complex grid using Java2d and I would be interrested in wether it is worth to group same operations together.

For example I have a 2-dimensional array and each zell in this array represents a zell in the grid, I do e.g. the following operations per zell in the follwing order:

every time:

  • setColor
  • fillRect

sometimes:

  • setColor
  • drawChars
  • setColor
  • fillPoly

The fills are always very small (not more than e.g. fillRect 12x18).
For each zell some arithmetical stuff is done.

Do you think it would be worth to group these operations at all or is it a waste of time?
For example first only setColor/fillRect and after this only setColor/drawChars - or may the same operations not be “interrupted” by a setColor? Or would it be beneficial to group the paints by color?

I am writing this espacially with the new accerlated pipelines (especially OGL) in mind.

Thanks in advance, lg Clemens

It is actually important to group similar operations if possible. This especially
helps when using accelerated pipelines as it reduces the state changes.

We’re trying to do as much batching as we can, but we can’t rearrange the order of
operations for you.

I made a presentation at this year’s JavaOne, where I actually have showed
the real difference (it was ~15% in some cases) in performance in grouping
vs not grouping.

Surprisingly, we even saw performance improvement for software pipelines.

The kind of stuff you’d want to group:
imaging operations
text rendering
non-aa drawing (basically draw* methods)
fills (fill* methods)
AA drawing
AA fills

Thanks,
Dmitri
Java2D Team

well, I thought re-arranging the operations is a good idea after reading your presentation :wink:

btw does setColor cause a state-change?

thanks in advance, lg Clemens

[quote]btw does setColor cause a state-change?
[/quote]
It doesn’t unless you change the translucency of the color from opaque to
translucent or vice versa.

Dmitri
Java2D Team