evil-mad / axidraw

Software for the AxiDraw drawing machine
GNU General Public License v2.0
430 stars 130 forks source link

Speed tests for 3.8 release #144

Closed oskay closed 1 year ago

oskay commented 1 year ago

Motivation

AxiDraw software release 3.0 made a significant change in how documents were processed as part of the plotting process:

Historically, this software [...] has parsed the SVG document essentially one element at a time, plotting each element, and then going onto the next element in the document. [...] This distributes the "up front" computation time for parsing different types of SVG elements across the duration of the plot.

Starting with version 3.0, a copy of the SVG document is now fully processed to create an intermediate "digest" prior to plotting [...]. This method adds overhead in terms of memory use and initial computation time [...]

The net effect is that some users upgrading from AxiDraw < 3.0 experienced that the software felt much slower even in cases where the total computation + plot time was unchanged. Since that release, we have become of some use cases -- with very large SVG files -- for which the initial delay before plotting was taking a very long time.

In AxiDraw 3.8, we have tried to make the software faster, particularly in that initial computation stage, and particularly for those very large SVG files. Rather than saying that the software is (say) "20% faster", or "up to 97% faster", we are documenting some specific measurements in this issue that highlight the actual changes, and demonstrate which types of things are now faster.

Test files and conditions

Five files were used for testing, some of them directly from users, some of them created from scratch to test particular corner cases. (These files do include user data and not made publicly available.)

File Size Length Notes
test.1svg 277 MB 1225 m 1.6 million polyline elements. Many short disordered segments that together form paths. Tests joining & optimization.
test2.svg 280 MB 760 m Only 80 paths, but each is very long. Tests path parsing & supersampling
test3.svg 6.3 MB 15 m Moderate size user file; 5500 short disjoint paths
test4.svg 12.2 MB 389 m Extremely high point density, tests supersampling.
test5.svg 32.8 MB 885 m Heavily nested transformed objects, high point density.

Default settings were used on all files, except that the model was set to 5 (SE/A1 size; some of the test files are large) for all tests and the gap joining threshold was reduced to 0.001 for all tests on file test1.svg (only).

All times measured are in seconds; lower is better, and these should be regarded as rough measurements only.*

(*Time measurements were made on a MacBook Pro computer with an Apple M1 Pro CPU, on Python 3.10, while the computer was otherwise being used as a normal computer. Some runs were verified with a second or third test to verify the rough time results. These results provide a useful, if rough, comparison, but we advise that no weight should be given past 2 significant digits in any result.)

Significant performance gains for initial processing of the SVG file, particularly for large input files.

Parsing and processing SVG, saving plot digest. Effectively measures time between initiating a plot and when the AxiDraw begins drawing (or, begins drawing when resuming a plot). Run with different options for plot optimization:

(-L5: model SE/A1. -T: Enable time reports. --digest 2: Only process file; don't print)

File Strict 3.7 Strict 3.8 Join 3.7 Join 3.8 Full 3.7 Full 3.8
test1.svg 78 34 161 122 161 121
test2.svg 1068 181 1085 178 1078 178
test3.svg 25 2.8 25 3.2 25 3.5
test4.svg 34 6.4 34 6.7 34 6.8
test5.svg 50 11 53 13 51 12

File parsing and processing times are significantly lower in AxiDraw 3.8; initial processing prior to optimizations is 50-80% faster, with little or no change in optimization times. Overall initial processing, including optimization time, is 25 - 85% faster, depending on the nature of the file.

Resume -> Home command is significantly faster

Starting with the files file paused about 50% through, and then using the resume home command:

time axicli test*.svg --mode res_home -L5 -v

File 3.7 3.8 3.7 (Plob) 3.8 (Plob)
test1.svg 83 12 12.2 5.57
test2.svg 1104 30 1.53 0.55
test3.svg 25 0.23 0.19 0.15
test4.svg 34 0.31 0.31 0.17
test5.svg 51 0.62 0.50 0.23

83 -> 12 s is not bad, but 1104 -> 30 s is a very good improvement. The tests designated "(Plob)" are ones that began with a Plob digest file, which means that most of the file parsing and processing was already handled prior to starting the job.

Multi-page previews are faster

Testing with optimization strictly disabled, previewing 1 page or 10, with otherwise default settings:

File 1pp 3.7 1pp 3.8 10pp 3.7 10pp 3.8 slope 3.7 slope 3.8
test1.svg 134 86 1411 84 141.9 ~0
test2.svg 1104 195 11407 193 1144.8 ~0
test3.svg 26 3.45 265 3.45 26.6 ~0
test4.svg 40 8.16 411 8.13 41.2 ~0
test5.svg 61 14 630 14 63.2 ~0

The slope columns give the amount of additional time, in seconds) to preview each additional page. While the baseline times to preview a page are shorter due to faster processing (see the tables earlier on this page), the added time per page is essentially zero here. That's because we added a trivial and obvious (in retrospect...) optimization: multi-page previews now simply multiply the time and distance for a single page, if the random_start option is disabled.

OK, but what if random_start option is enabled?

(* Random start does not significantly affect the execution time for a single page here.)

File 1pp 3.7 1pp 3.8 10pp 3.7 10pp 3.8 slope 3.7 slope 3.8
test1.svg 134 86 1383 558 138.8 52.4
test2.svg 1104 195 11235 423 1125.7 25.3
test3.svg 26 3.45 267 8.94 26.8 0.6
test4.svg 40 8.16 403 25 40.3 1.9
test5.svg 61 14 382 45 35.7 3.4

With random_start enabled, each individual page is fully previewed (the motion profile for the entire document is computed, so that there is a full record of the time and distance). The additional time per page (differential or marginal, depending if you come from science vs economics) is not zero, but it is significantly lower in AxiDraw 3.8 than AxiDraw 3.7.