-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate non-CSG speedup initiatives [Do not merge] #4654
base: master
Are you sure you want to change the base?
Conversation
Can give up to 10% speed up of rendering of models like this: $fn=1000; sphere(); translate([0.5, 0, 0]) sphere();
This allows using getArray repeatedly during construction of the reindexer without incurring quadratic costs because of array rebuilding
IndexedFace intermediate stage wasn't needed (possible now that Reindexer's vector is usable during construction)
- use strtof instead of istringstream! - skip tests about polygons w/ duplicate vertices (guaranteed not to happen after tesselation) - cache tostring / fromstring results for each unique vertex - normals are now... normalized (-0 -> 0)
…oSequentialAssignment)
I thought about this for some time, I think it is hard to get decent performance without doing some kind of large refactor, as AST traversal and allocations for stack frames are slow in general. We also don't have jit, which can speed up numerical code by a lot. I wonder if it will be a good idea to look into translation into lua for example, which has good FFI and a pretty fast jit. V8 will probably be faster, but not sure if the FFI is as simple. By writing the translation rules, we can also fix some unclear semantics issues... |
Other possibly tricky avenues of optimizations:
Yess!! Tbh I've been toying with the idea of transpiling OpenSCAD to heavily templated C++ (which in turn, would use parallel constructs, Eigen matrices, etc). Advanced static analysis w/ type propagation / static tracing could bring us quite far. Definitely worth looking at the semantics of Lua, JS, and general options that have few dependencies (and work well w/ emscripten). I've done a fair bit of V8 native interfacing (codegen), it has a solid API. My main concern right now is I don't fully understand OpenSCAD's semantics, will need a deep dive into its possibly undocumented fine-print that enables some of the magic leveraged by libs like BOSL2. |
There are also issues regarding caching, e.g. #782. I think I can find some time later to hack a simple bytecode interpreter and see how far can we go with something naive. |
It seems like it should be possible to fully resolve non-$ variable, function, and module references at parse time. (But I haven't done any analysis on how much that would save.) |
Yes, those are just static scoping. Typically you will save time in computing the hashes and creating the hash tables. These are small gains, but can be pretty large if they are in the hot path (which they are...) |
I don't immediately understand why you would need hashes or hash tables for them. It seems like you could just have pointers directly to the underlying $ variables are entirely different, of course. |
Ah, poor wording. What I meant is you will save time from computing those hashes. You can use pointers to point to the underlying values, or have a stack of values stored inline (avoid allocation per value) and use indices to those values directly. |
Now that 3D CSG operations are super fast (with experimental features manifold or fast-csg), the rest of OpenSCAD (script evaluation, import, export) can become the bottleneck on some more ambitious models (note: I'm only looking at CLI rendering times, not UI / rendering, although this will impact preview times).
This PR is an umbrella to list, discuss and merge-integrate some active efforts towards non-CSG speedups (have been tested separately and should provide speedups of at least 5% each on some model - sometimes on the script evaluation phase only, e.g. tested w/
--export-format=echo
):(uses indexed meshes & double-conversion library)
Identifier to pre-hash and intern variable lookup strings
(both for # of polygons and # of vertices in each polygon)
(takes some hashmaps out of hot evaluate codepaths)
Upcoming (not merged yet in this draft PR as not stable yet):
Results (WIP, benchmarks here) (all assuming
--enable=manifold
):sphere(10, $fn=1000);
: 2.83x faster to binstl, 5.92x faster to asciistlsphere($fn=1000); translate([0.5, 0, 0]) sphere($fn=1000);
: 1.22x faster to binstl, 1.78x faster to asciistl