Skip to content

How to improve JavaFX Clip performance #2

@yososs

Description

@yososs

With the following changes, the JavaFX clip benchmark fps is now
My macbook has improved to 28fps.

JavaFX's GraphicsContext implementation allocates a canvas-sized texture for each call to the clip method, making multiple calls costly. This can be confirmed with the following jvm option.

-Dprism.printallocs=true

It can be improved to a practical fps by performing clips all at once as follows.

		gc.save();
		gc.beginPath();
		for (int y = 5; y <= height - 25; y += 25) {
			for (int x = 5; x <= width - 25; x += 25) {
				gc.save();
				gc.translate(x, y);
				gc.moveTo(10, 10);
				gc.arc(10, 10, 10, 10, 0, 360);
				gc.arc(10, 10, 5, 5, 0, 360);
				gc.restore();
			}
		}
		gc.clip();

		gc.setFillRule(FillRule.EVEN_ODD);
		for (int y = 5; y <= height - 25; y += 25) {
			for (int x = 5; x <= width - 25; x += 25) {
				gc.setFill(Color.color((double) x / width, 0.5 * (1 - x / width), (double) y / height));
				gc.save();
				gc.translate(x, y);
				gc.fillRect(0, 0, 20, 20);
				gc.restore();
			}
		}
		gc.restore();

In addition, specifying the following jvm option will increase by a few fps.

-Dprism.marlin.profile=speed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions