Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved transcoding from SVG to Image #1428

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

stephanr
Copy link
Member

This PR was part of #1202 and the SvgImageTranscoder get reworked, as it was used there i a different way.

It replaces the the current way of transcoding (SVG -> PNG-Stream -> BufferedImage) by implementing org.apache.batik.transcoder.image.ImageTranscoder which gives direct access to the BufferedImage instead of using org.apache.batik.transcoder.image.PNGTranscoder .

A simple performance comparison was done on my local system by executing the following class five times with 100 iterations each.

package org.deegree.rendering.r2d;

import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import org.deegree.style.styling.components.Graphic;

public class SvgRenderPerformanceTest {

    public static void main( String[] args ) {
        new SvgRenderPerformanceTest().run();
    }

    public void run(){
        Rectangle2D.Double rect = new Rectangle2D.Double( 0, 0, 50, 50 );
        Graphic g = new Graphic();
        g.size = 50;
        g.imageURL = getClass().getResource( "similaritytests/gym.svg"  ).toExternalForm();
        BufferedImage img;

        long  tend, tstart = System.currentTimeMillis();
        for ( int i = 0; i < 100; i++ ) {
            // recreate renderer to prevent cacheing
            img = ( new SvgRenderer() ).prepareSvg( rect, g );
        }
        tend = System.currentTimeMillis();
        System.out.println("100 iteration took " + (tend-tstart)+" ms");

    }
}

This results into roughly 25% less time used to render a single SVG image 100 times. (Win10, Temurin 11, CPU 6x3.0Ghz)

  • Before (ms):
    • 2464
    • 2379
    • 2461
    • 2396
    • 2441
  • After/With SvgImageTranscoder (ms):
    • 1813
    • 1812
    • 1798
    • 1834
    • 1855

@stephanr stephanr added enhancement enhancement or improvement WMS deegree Web Map Service labels Nov 18, 2022
@stephanr stephanr added this to the 3.5 milestone Nov 18, 2022
@tfr42 tfr42 merged commit 9f61f26 into deegree:main Dec 7, 2022
@tfr42 tfr42 changed the title Speed up transcoding SVG to Image Improved transcoding from SVG to Image Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement enhancement or improvement WMS deegree Web Map Service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants