crocoddyl icon indicating copy to clipboard operation
crocoddyl copied to clipboard

Memory usage skyrocketed since moving to header-only

Open wxmerkt opened this issue 4 years ago • 17 comments

Since moving to header-only in #695, the memory usage during compilation sky-rocketed:

image

Is there any way to use precompiled headers or something to make it more manageable?

wxmerkt avatar Mar 11 '20 11:03 wxmerkt

Some of it is expected. How many threads are you using for compilation?

proyan avatar Mar 11 '20 12:03 proyan

12 threads/full CPU by default but it exceeds 16GB with/after 3 threads. I am aware it's expected but is there a way to reduce it though?

wxmerkt avatar Mar 11 '20 12:03 wxmerkt

I think we can be a bit smarter when including headers. This would be the first step. But I don't think I can handle it immediately, it would have to wait atleast till next week.

proyan avatar Mar 11 '20 14:03 proyan

The memory could be reduced it by splitting the implementation of a classe. Let's say for the DifferentialActionModelContactFwdDynamcs class, we have

  1. contact-fwddyns-calc.hpp and contact-fwddyns-calcdiff.hpp
  2. contact-fwddyns-calc.cpp and contact-fwddyns-calcdiff.cpp

This could be done for few classes that are needed (such contact and impulses differential action models) @nim65s is a good practice to do this?

cmastalli avatar Mar 18 '20 15:03 cmastalli

It's easier to compile many smaller .o and link them later in a big .so, yes.

Smaller source files comes with a better readability, a more granular recompilation and caching, and easier merges.

nim65s avatar Mar 18 '20 15:03 nim65s

@nim65s thanks for the answer

@wxmerkt could you let me know which classes are memory hungry? Let's figure out a plan of attack for this issue.

cmastalli avatar Mar 18 '20 15:03 cmastalli

The most memory hungry were free-fwd-dyn.hxx and contact-fwd-dyn.hxx. You can measure before/after using /usr/bin/time -v make -j1

wxmerkt avatar Mar 18 '20 16:03 wxmerkt

@cmastalli are you taking care of this?

proyan avatar Mar 20 '20 18:03 proyan

I'm not working on it now.

If you decide to work on it, then assign this issue to you. I'll do the same.

cmastalli avatar Mar 20 '20 19:03 cmastalli

@proyan I won't work on this task. This task is not near to be priority for me. I am imposing myself to follow the rule if it ain't broke don't fix it since I can't spend my time on these activities.

If someone doesn't offer his/her help within a week, then I would close this issue. It is not useful to keep issues that are not going to be handle.

Does somebody disagree?

cmastalli avatar May 08 '20 17:05 cmastalli

We should keep the issue open. Issues should only be closed if they are resolved. This issue is a real problem unless you have 64GB RAM.

wxmerkt avatar May 08 '20 17:05 wxmerkt

I've noticed a further spike in compilation time (to ~35mins with Python bindings, examples, no unit tests) and memory usage for devel recently (from perhaps December to now): Using 12 threads, I now commonly exceed 64 GB memory with another 17 GB swapped during peak: image

This is using a i7-9850H (all cores in boost at 3.96 GHz, 12 MB cache). Are you seeing similar times or resource use? Is there something we can do about this?

wxmerkt avatar Feb 08 '21 15:02 wxmerkt

I don't have the consumption that you have, with Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz, and 8MB L3 Cache. I peak out at 20GB with 8 cores. Memory is definitely a problem, and there are some obvious solutions to this (as @nim65s pointed out). But the problem right now is the available manpower behind this issue. Unfortunately, I think for most of us this is low on priority.

Are there any simple fixes we can make to improve this, which don't require big refactoring of the code?

proyan avatar Feb 08 '21 15:02 proyan

Don't use gcc but llvm/clang instead ;)

jcarpent avatar Feb 08 '21 16:02 jcarpent

@wmwrkt and @proyan -- could you report the compilation performance with clang (as suggested by @jcarpent)?

cmastalli avatar Feb 08 '21 19:02 cmastalli

From periodic visual inspection, memory usage topped out at ~32GB. The compilation finished in 12min49s which is considerably less than the ~35mins with gcc. Thanks for the suggestion @jcarpent :-).

wxmerkt avatar Feb 08 '21 20:02 wxmerkt

The perf I specified is with clang, so @jcarpent's suggestion checks out :)

proyan avatar Feb 08 '21 20:02 proyan