0

I have the follow struct in C++ on iOS, and am wondering if it is a problem, performance wise. I have been reading on cache line access and minimising them for optimal performance. I understand that on iOS, the newer chips have a cache line size of 32bytes.

I have the following struct in my app.

struct globalSynthParams
{
    globalVoiceParams       voiceParams;
    globalOscillatorParams  osc1Params;
    globalOscillatorParams  osc2Params;
    globalOscillatorParams  osc3Params;
    globalOscillatorParams  osc4Params;
    globalOscillatorParams  lfo1Params;
    globalOscillatorParams  lfo2Params;
    globalFilterParams      filter1Params;
    globalFilterParams      filter2Params;
    globalEGParams          eg1Params;
    globalEGParams          eg2Params;
    globalEGParams          eg3Params;
    globalEGParams          eg4Params;
    globalDCAParams         dcaParams;
};

When I run the sizeof() for each inner struct, it gives me:

Size of globalVoiceParams: 200
Size of globalOscillatorParams: 56
Size of globalFilterParams: 24
Size of globalEGParams: 24
Size of globalDCAParams: 8
Size of globalSynthParams: 688 (the total size of the above struct) 

Is this considered bad struct planning? Would there be any tangible performance improvement if I break up the structs such that they fit within a cache line or 2? I have checked the inner structs, they are packed nicely.

Some other articles I've read.. What is "cache-friendly" code?

Many thanks for your insights.

EDIT: In relation to the above question, what exactly am I doing when I am doing the below?

m_dAmplitude = osc3Params->dAmplitude; // osc3Params is part of the above struct

Am I loading the entire globalSynthParams struct into memory and accessing the osc3Params struct from there?

Community
  • 1
  • 1
lppier
  • 1,927
  • 3
  • 24
  • 62
  • First, I doubt that cache misses are the greatest performance issue in your program. Second, what's wrong with the size/order of your structs? I don't understand what worries you. If you can make them smaller, it could help. But reordering them isn't really going to accomplish much unless you know for sure there is some kind of access pattern that is problematic. – JS1 Feb 28 '15 at 06:37
  • @JS1 there isn't a problem ... I'm just optimizing my code to run at the fastest speed possible. That's why I asked if there's any tangible performance improvement in this case. The struct variables are access at sample rate so many there is something here, I thought. – lppier Feb 28 '15 at 10:30
  • Sorry.. "The struct variables are accessed at sample rate so maybe there is something here, I thought." typo – lppier Feb 28 '15 at 14:01

0 Answers0