1
0
mirror of https://github.com/horst3180/arc-icon-theme synced 2024-10-27 19:34:01 +00:00

Improve performance by dividing up tasks

The stream of inkscape commands have been divided across multiple
instances of inkscape, one per core. This speeds up rendering by
using more cpu cores, even for single svg rendering. To do this a
simple java program was written which starts N instances of
whatever arguments was passed to it and then reads one line at the
time from standard input, the lines are then divided into N
seperate streams which are then piped to the the difference instances
of whatever program was passed as argument to SplitJob.
This commit is contained in:
Christer Jensen 2017-08-31 06:17:20 +02:00
parent 1922bf0525
commit 525b4a2663
3 changed files with 56 additions and 3 deletions

BIN
src/SplitJob.class Normal file

Binary file not shown.

54
src/SplitJob.java Normal file
View File

@ -0,0 +1,54 @@
import java.io.*;
import static java.lang.ProcessBuilder.Redirect;
public class SplitJob {
private static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) {
final Runtime runtime = Runtime.getRuntime();
int numThreads = runtime.availableProcessors();
Process[] procs = new Process[numThreads];
try {
ProcessBuilder builder = new ProcessBuilder(args);
builder.redirectError(Redirect.INHERIT);
for (int i = 0; i < numThreads; i++) {
procs[i] = builder.start();
}
for (int i = 0; ; i = (i + 1) % numThreads) {
String s = in.readLine();
if (s == null)
break;
byte[] data = (s + '\n').getBytes();
procs[i].getOutputStream().write(data, 0, data.length);
procs[i].getOutputStream().flush();
}
for (Process proc : procs) {
proc.getOutputStream().close();
int exitCode = proc.waitFor();
if (exitCode != 0) {
System.err.printf("[Error] %s stopped with exit code: %d\n", args[0], exitCode);
System.exit(2);
}
}
} catch (Exception e) {
System.err.printf("[Error] %s: %s\n", e.getClass().getName(), e.getMessage());
System.exit(1);
}
}
}

View File

@ -68,13 +68,12 @@ do
# since we finished rendering it out last.
if [[ $CONTEXT.svg -nt .${CONTEXT}_timestamp ]]
then
genInkscapeCmds $CONTEXT | $INKSCAPE --shell > /dev/null && touch .${CONTEXT}_timestamp &
echo "Rendering icons from $CONTEXT.svg"
genInkscapeCmds $CONTEXT | java SplitJob $INKSCAPE --shell && touch .${CONTEXT}_timestamp
else
echo "No changes to $CONTEXT.svg, skipping..."
fi
done
wait
# Remove all empty directories from the theme folder.
find $THEMEDIR -type d -empty -delete