I have a program that uses Gnuplot to generate SVG charts. My program creates a child gnuplot.exe process and then pipes the input to stdin. This is on a Windows system. My program generates hundreds of charts, so I am sensitive to performance. I am currently using an older version of Gnuplot (version 5.4.2). When I upgrade to the latest version (version 5.4.8), my program takes about 20 times longer to execute. This is a very noticeable performance degradation. The problem seems to be related to the way the Windows build of Gnuplot receives data from stdin.
I have created a standalone program that illustrates this issue. You can find the source code and build instructions here:
https://github.com/jkillingsworth/gnuplot-perf
You can use the following command to clone the repo:
git clone https://github.com/jkillingsworth/gnuplot-perf.git
This program benchmarks the performance of piped input for versions 5.4.2 and 5.4.8. The C++ code can be built using MSYS2 or MSBuild. You can also run it from within the Visual Studio IDE. As an alternative, I have provided a C# and F# variant that can be compiled using the .NET SDK. The repo also includes command line scripts that demonstrate the performance issue without having to build the program from source.
I have done some investigating in the Gnuplot commit history. It looks like there are two commits in particular that are relevant to this issue:
780f8bd 2022-02-15 13:44:15 Takashi Yano
a501a67 2021-07-10 11:41:40 Bastian Maerkisch
The commit messages associated with these changes suggest that they contain speed improvements. However, I have not been able to validate this. Commit a501a67 introduces a bug that sometimes omits characters piped in from stdin (see bug #2491), but it doesn't seem to have any noticeable effect on performance. Commit 780f8bd fixes the bug, but hinders the performance by a factor of 20.
It is possible that I am doing something incorrectly, in which case I could use some guidance. I have studied some of the code in src/win/winmain.c, but I don't fully understand it yet. The issue seems to be related to changes made to the MyFGetS function in commit 780f8bd.
I would like to make the piped input run as fast as possible. I have an MSYS2/MINGW64 environment set up on my local machine, and I am able to build Gnuplot from source. I am willing to test out any suggestions or experimental patches related to this issue. Also, I can give assistance to anyone having trouble running my benchmarking program.
For Msys2/Mingw-w64 build, you can get a build instruction : https://sourceforge.net/p/gnuplot/support-requests/199/