Skip to content

Performance optimization of the Vector class#762

Merged
phkahler merged 1 commit intosolvespace:masterfrom
ruevs:VectorOptimisations
Oct 24, 2020
Merged

Performance optimization of the Vector class#762
phkahler merged 1 commit intosolvespace:masterfrom
ruevs:VectorOptimisations

Conversation

@ruevs
Copy link
Member

@ruevs ruevs commented Oct 21, 2020

Profiling with MSVC 2019 showed that many of the Vector methods are on a critical path (not surprising). They are changed to be inline and unnecessary temporaries are removed.

On the example below generate times decreased from 102s. to 64s.
At the same time the executable size shrank from 5569536 to 5150208 bytes in release mode (with global optimizations).

This should not stop us from working on optimizing inner loops e.g. #759 .

Test model

Profiling results:
20201021_Profiling_Before.txt
20201021_ProfilingAfterVectorInline1.txt
20201021_ProfilingAfterVectorInline2.txt
20201021_ProfilingAfterVectorInline3.txt

@ruevs ruevs force-pushed the VectorOptimisations branch from 3fc6df1 to 06a2dfb Compare October 21, 2020 15:15
@ruevs
Copy link
Member Author

ruevs commented Oct 21, 2020

Very interesting. GCC complained about more of the inline functions than MSVC...
XCode on the other hand was fine.

I would have tried with MinGW GCC but the "mimalloc" library we started using breaks both GCC and clang on windows since it uses <bcrypt.h> <winternl.h> headers that are included only in the Microsoft SDK :-(

I'll move the ones the Travis build complained about in the header. Tomorrow...

@phkahler
Copy link
Member

Also, please don't remove Negated or MakeMaxMin I was actually looking for MakeMaxMin earlier but didn't notice it. I'll be using it soon.

Also, I'm not familiar with that syntax: return { a,b,c } has that been possible for a long time or more recent? Either way I think I like it.

@phkahler
Copy link
Member

Never mind, I see you moved them to the header file.

@ruevs
Copy link
Member Author

ruevs commented Oct 22, 2020

Also, I'm not familiar with that syntax: return { a,b,c } has that been possible for a long time or more recent? Either way I think I like it.

It's C++11 - returning list initialized objects directly is possible:
https://en.cppreference.com/w/cpp/language/list%20initialization

  1. in a return statement with braced-init-list used as the return expression and list-initialization initializes the returned object

I checked the generated assembler and is makes it more compact (event with full optimizations) by not asking the compiler to create a local variable on the stack. When inlined I hope it helps even more.

Profiling with MSVC 2019 showed that many of the Vector methods are on
a critical path (not surprising). They are changed to be inline and
unnecessary temporaries are removed.

On the example below generate times decreased from 102s. to 64s.
At the same time the executable size shrank from 5569536	to 5150208 bytes
in release mode (with global optimizations).

This should not stop us from working on optimizing inner loops e.g. solvespace#759 .

[Test model](https://github.com/solvespace/solvespace/files/5414683/PrismConeNURBSNormalsTangents300.zip)
@ruevs ruevs force-pushed the VectorOptimisations branch from 06a2dfb to c6a06e7 Compare October 23, 2020 19:02
@phkahler phkahler merged commit 7035071 into solvespace:master Oct 24, 2020
@phkahler
Copy link
Member

@ruevs this has little effect on that sketch I've been using as a benchmark (which is down to 8s on LTO master) but it does have a very perceptible improvement in the smoothness of dragging shapes with compound curvature like resizing a torus or dragging control points of the curved surface from issue 315. Different sketches, different bottlenecks. Nice improvement here!

@ruevs ruevs deleted the VectorOptimisations branch October 24, 2020 08:07
@ruevs
Copy link
Member Author

ruevs commented Oct 24, 2020

The credit goes entirely to MSVC 2019 which makes profiling extremely easy. These were just the "low hanging fruit" :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants