From: Matthew Fernandez Date: Fri, 21 May 2021 02:34:36 +0000 (-0700) Subject: optimize two calls to gvprintf with single characters X-Git-Tag: 2.47.3~31^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c54470e710964d566bce944befcbd048c0581567;p=graphviz optimize two calls to gvprintf with single characters The expression `gvprintf(j, "%c", x)` is equivalent to `gvwrite(j, &x, 1)`. However, it seems modern compilers, even with link-time optimization enabled, are not clever enough to see this equivalence. By unraveling the gvprintf call to what it eventually bottoms out to, we can accelerate SVG generation. On tests/regression_tests/large/long_chain, this drops the number of gvprintf calls from 297008 to 165008, reducing the amount of the trace for which gvprintf is responsible from 3.27% to 2.24%. Total executed instructions are reduced from 8160974807 to 8098098396, a speed up of ~1%. --- diff --git a/plugin/core/gvrender_core_svg.c b/plugin/core/gvrender_core_svg.c index 8a6c4989b..a852b4db1 100644 --- a/plugin/core/gvrender_core_svg.c +++ b/plugin/core/gvrender_core_svg.c @@ -59,7 +59,7 @@ static void svg_bzptarray(GVJ_t * job, pointf * A, int n) if (A[0].x <= A[n-1].x) { #endif for (i = 0; i < n; i++) { - gvprintf(job, "%c", c); + gvwrite(job, &c, 1); gvprintdouble(job, A[i].x); gvputs(job, ","); gvprintdouble(job, -A[i].y); @@ -71,7 +71,7 @@ static void svg_bzptarray(GVJ_t * job, pointf * A, int n) #if EDGEALIGN } else { for (i = n-1; i >= 0; i--) { - gvprintf(job, "%c", c); + gvwrite(job, &c, 1); gvprintdouble(job, A[i].x); gvputs(job, ","); gvprintdouble(job, -A[i].y);