Jump to content

Memory allocation when entering case structure


Tim_S

Recommended Posts

Posted for the next person to run into this (it could always be me!).

 

Backstory: I was testing performance of some RT code and it was coming out lousy. I tracked the slow performance down to where I was reading and writing a linear buffer in a VI. The write was taking 88 msec and the read was taking over 300 msec. I brought the code over to Windows side and was getting pretty bad performance there (write was 1 msec).

 

[Omit lots of head scratching, improvement attempts, call to NI tech support, obligatory waving of dead chicken...]

 

There were two things that improved the performance:

1. Eliminating the bundle/unbundle of cluster elements

2. Wiring through case structures

 

There is some cost hit with the bundle/unbundle. I didn't determine how much improvement eliminating them created. My solution was to eliminate my cluster and use a shift register for each element of the cluster. Tech support came up with using the in place element structure.

 

Wiring through the case structure created the best benefit for me. Tech support was able to relate about the case structure and memory allocation, "The compiler is going to create duplicate copies of the array when branching and when going into a case structure to make sure that we operate on good array data every time (regardless of which case is executed)..." My test code was branching a 1M element U32 array, so I was getting a serious performance hit from the copy. This copy does not show up when using the Show Buffer Allocations tool (LV 2012). Tech support was able to identify the allocation using the Desktop Execution Trace Toolkit.

 

All said-and-done, the relative performance on a Win7-64 with LV2012-32:

Original: 1046 usec

Using IPE: 31 usec

Using shift registers: 26 usec

 

Tech support organized the back-and-forth and sent a project demonstrating the difference; I've included that. Buffer Testing Project.zip

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.