-
Notifications
You must be signed in to change notification settings - Fork 537
Minor refactoring of surface curve data into its own struct #1536
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
base: master
Are you sure you want to change the base?
Conversation
3cfba9a to
258c669
Compare
This allows keeping its functionality together and gives us the ability to copy it separately when needed, avoiding a copy of the entire surface data. This was the case in `MakeFirstOrderRevolvedSurfaces()` as well as in `SplitInHalf()` -- both of which have been converted to work on the curve data alone.
|
This may avoid copying a few bytes here and there (as in However if you have an example model where profiling shows that this change causes a significant speed up or is on the critical path we should consider it. |
|
@iscgar Are you saying that SplitInHalf is doing a deep copy of all the trims? That should not be happening, but if it is we should fix it for performance reasons. BTW we don't care about copying the color or handle, that's very minor. My biggest with this issue is that names are important. In Solvespace a curve is a one-dimensional curve either in a plane or in 3d space. A surface is a 2-D surface in 3-D space. We don't want to use curve terminology for a surface data structure - that's just confusing. Second complaint is that this just takes more text to specify a piece of data. Almost every line of the diff is just adding the extra colons and the word "curve" to the code. |
Right now this is indeed only copying a few additional bytes because copying a But as I noted in my reply to your comment there, I'm working on reworking the way As part of that change I also made the following conversions to code that copied
In that context, copying the entire
As I explained above, no deep copy is performed with the existing code.
Both valid points, and I fully accept your reservations (especially in light of @ruevs 's comment in the other PR about avoiding disturbing the existing code as much as possible). However, assuming my reason for making this change seems reasonable, I'm open to suggestions for a better term, or to thinking of other ways to achieve the same result without introducing another nesting level. |
This reverts commit 258c669.
You will not be the first one ;-) with help, ideas and inspiration from: @Evil-Spirit In general keep in mind these when working on performance: Test models to profile with: Last time I profiled (about half an year ago, but nothing performance related has changed since) neither List nor IdList were a bottleneck. For example on this #759 (comment) most of the time was spent on axis aligned bounding boxes :-) A torture test model for IdList is here: and one more: More wisdom from @rpavlik (shallow copy is intentional) #932 (comment) Test and profile with various models in release mode (with optimisations on and debug info for profiling). A debug build is no indication at all about the real performance and bottlenecks. In short - I'm very exited that you have started looking deeply into SolveSpace and am very curious what will come out of it. What platform are you on? |
|
@ruevs thanks for the links to past discussions and ideas! I've seen some of them, but definitely not all of them. I'll make sure to take the information in them into account before I submit my work. I'm on Linux, but I'm also running on Windows every once in a while. |
In `MakeFirstOrderRevolvedSurfaces()` as well as in `SplitInHalf()` a full copy of `SSurface` is made even though only a small part of it is needed. Change the code to copy only the necessary data.
|
I added a different approach to achieve the same result, which hopefully addresses the concerns raised (assuming such a change seems reasonable despite not having an impact on the existing implementation). I intentionally did it by adding a revert commit and then the new approach, so that the two approaches could be compared easily. If the change is acceptable, I'll remove the first two commits. |
|
One possible reason to put the raw Rational Bezier Surface data into a separate struct within SSurface would be to abstract the underlying surface type (later - much much later) so someone could implement other types of surfaces, or just more generalized NURBS surfaces. So if we allowed that, there must be a mathematical word for "the surface that the trim polygon defines a subset of". We'd want to name it that instead of curve (It must not be curve! ;) and maybe use an abbreviation. |
|
I only used But that's assuming we indeed want to go this way instead of just changing the two places where this will become relevant with my other changes. |
Here is a model As you can see currently the bottleneck is not The recursive solvespace/src/srf/raycast.cpp Line 215 in bd7b627
Reduces the loading time from 15.1s to 13.9s on my machine. The critical path is still the same, but a bit faster. @phkahler perhaps we should #ifdef DEBUG those lines? |
|
From a performance perspective, I think optimizing low level data structures is a waste of time. Even the OpenMP stuff is kind of a hack (but a really good one). The real performance problems come from algorithms that are O(n^2) and higher. The fix for those things will be a spatial index to reduce the number of things tested against other things. I've got an index in mind but using that would make the code more complex and harder to fix the bugs we still have in the NURBS code. We're still in the "make it work right" phase but some "make it fast" changes are still OK. BTW a major bottleneck for a lot of things is the silhouette edges being rendered. Turn those of in the GUI ;-) Even the first item in the old wishlist is related to algorithmic complexity. That is still an O(n^2) algorithm. |


This allows keeping its functionality together and gives us the ability to copy it separately when needed, avoiding a copy of the entire surface data.
This was the case in
MakeFirstOrderRevolvedSurfaces()as well as inSplitInHalf()-- both of which have been converted to work on the curve data alone.