Ultimaker / CuraEngine

Powerful, fast and robust engine for converting 3D models into g-code instructions for 3D printers. It is part of the larger open source project Cura.
https://ultimaker.com/en/products/cura-software
GNU Affero General Public License v3.0
1.68k stars 883 forks source link

Cache extruder settings #1867

Closed sesse closed 1 year ago

sesse commented 1 year ago

Description

When writing GCode, there are certain settings that need to be checked over and over again. Instead of pulling them from the Settings hash table every time, read them once and then save them. This speeds up single-threaded slicing by about 3% (one thread of a 5950X; with many threads, it seems to be more like 10%, since GCode writing then takes proportionally more of the time).

There is a very large long tail of code that keeps reading these settings, in particular from mesh settings, so there is probably more to be gained here, but this patch takes out the two biggest cases.

Type of change

Performance optimization.

How Has This Been Tested?

Only marginally; verified that a simple slice gives the same GCode, modulo timestamps and similar. Benchmarking has been done partially with perf, but verified with hyperfine (the times are fairly consistent from run to run):

Benchmark 1: ./run-cura.sh ./build/Release/CuraEngine.old
  Time (mean ± σ):      3.025 s ±  0.062 s    [User: 3.017 s, System: 0.010 s]
  Range (min … max):    2.910 s …  3.121 s    100 runs

Benchmark 2: ./run-cura.sh ./build/Release/CuraEngine
  Time (mean ± σ):      2.974 s ±  0.036 s    [User: 2.967 s, System: 0.009 s]
  Range (min … max):    2.824 s …  3.020 s    100 runs

Summary
  './run-cura.sh ./build/Release/CuraEngine' ran
    1.02 ± 0.02 times faster than './run-cura.sh ./build/Release/CuraEngine.old'

Test Configuration:

Checklist:

MariMakes commented 11 months ago

Quick update from our side 👋

Due to a miscommunication, your contribution was not mentioned in the 5.5 beta release. I'm restoring that, and making sure you get the correct credits in the 5.5 stable release.

Thanks again for your contribution 💖

sesse commented 11 months ago

Thanks for being diligent about it!