C ++ "delete" is slow. Where should I look first?

I have a C ++ application where the delete function is slow. What can cause this and where should I start looking for a solution?

Background:

This C ++ code is located in an ARX file running inside AutoCAD, which basically is just a DLL.

The specific computer that is running slow deceleration starts AutoCAD 2011, Windows 7, 64-bit. ARX ​​for AutoCAD 2011 must be compiled using Visual Studio 2008 Service Pack 1.

A computer with a problem is a client computer. There is no installed version of Visual Studio on it.

On my development computer, the code has no problems in AutoCAD 2011.

To check, I have code that removes a linked list. On a computer with a problem, it takes 0.7 seconds to delete the list. On computers and configurations, the same code takes 0.02 seconds without any problems. Specific times are not important - there is a big difference between the two numbers.

I am sure that I am running the same version of code on both computers, so the issue with debugging is not a problem.

+7
source share
5 answers

Roughly in the order in which I would check them:

  • Other plugins: could this lead to other ARX files? Can they be disabled on a bad system?
  • PerfMon: Check if the page breaks during a weak / hard break or cache misses during deletion (I hope you can install this on the clients computer).
  • HeapQueryInformation: same values ​​in good / bad environment?
  • Heap Lock . Could some other thread be very active in the background, holding onto the heap lock? You can test by wrapping the loop in HeapLock / HeapUnlock (and the time inside the castle, of course).
  • Hooks: Can the corresponding code connect? (for example, a third-party application connects to the C ++ / Win32 heap functions to do whatever it wants)
  • Grasping on straws: Do new an unusually long time? How is individual delete time allocated?
+5
source

May be due to different cache efficiency between working / system failure. There may be more memory fragmentation in the system failure, which means that a large delete deletes the cache. On a quiet system, data may be more consistent and get more cache attempts during a large delete.

Try Intel Performance Monitor?

+1
source

If this is acceptable and possible, try using the profiler on the client computer.

You can try AMD CodeAnalyst or Intel Profiler (although this one is not free).

If this is not possible, add the profiling code to your build versions and get the results from the client. Even simple profiling code can help you find the real bottleneck.

It doesn't seem like the problem itself is a problem, but the problem may be in some part of the code.

eg. - What is the type head->resval.rstring ?

+1
source

We run into this all the time. There is nothing wrong with the code, removing thousands of elements can take several seconds (and I saw how it got to minutes) even in Release mode.

Answer: do not delete. Get yourself a real memory allocator, and instead of individually distributing each object, create a memory pool (or a user heap or whatever you want to name). Nedmalloc is what we use and recommend, and you can create "nedpool". Basically, a pool is a block of memory from which your objects will be allocated. You still allocate memory for each object, but it is taken from the pool, and not directly from the OS.

When the deletion time comes, you simply delete the entire pool, and not delete objects one by one. Use different pools for each batch of objects that expire at the same time. You do not need to allocate memory for the entire pool, but you can delete it all right away.

0
source

How is the list registry created? Also, is there a reason you select and delete resbuf manually instead of using acutNewRb and acutRelRb?

In addition, you probably checked them, but does the user have a default drawing loaded in both AutoCAD 2009 and 2011? If not, are the drawings the same (except for the ACAD version), and are they located locally or on a network drive? You can also see if the user has the same lisp / applications. Net / objectARX working in both instances. Also, is AutoCAD 2011 a network or local installation?

Finally, you can add the autocad and objectarx tags to the question.

0
source

All Articles