ACE3 icon indicating copy to clipboard operation
ACE3 copied to clipboard

Optimise unit wound storage

Open kymckay opened this issue 6 years ago • 8 comments

The way we currently store wounds on units (in QEGVAR(medical,openWounds)) means we have to loop through the whole array at many points in the code to filter out the ones we aren't interested in.

There's already a comment to remove one element from the wounds array (the ID which is seemingly never used), but beyond that I believe we could be storing these in a much more efficient way if we were using some form sorting or key/value system to speed up retrieval.

This is fairly low priority and would be a nice refactor to do once functionality is all in place.

kymckay avatar Jul 23 '18 16:07 kymckay

probably just using a CBA hash is enough? And then seperate by wound type or place?

dedmen avatar Jul 23 '18 16:07 dedmen

Yeah was my first thought too. If I was doing it in python I'd have a series of dicts first separating by bodypart and then by wound type:

all_wounds = {
    'head': {
        'abrasion': {},
        ...
    },
    'body': {},
    'arm_l': {},
    'arm_r': {},
    'leg_l': {},
    'leg_r': {}
}

kymckay avatar Jul 23 '18 17:07 kymckay

I do not think this should be part of the medical rewrite, but instead a follow up once that is done. I'd therefor opt to put this on a different milestone instead.

thojkooi avatar Jul 23 '18 17:07 thojkooi

Agree. Optimization in general can be done after. Rather get this out quickly and then optimize together with minor bugfixing.

dedmen avatar Jul 23 '18 18:07 dedmen

I also agree on both suggestions: delay until the rewrite is finished and on the use of CBA hashes.

TheMagnetar avatar Jul 24 '18 09:07 TheMagnetar

Should we get a seperate milestone for post-rewrite changes?

dedmen avatar Mar 26 '19 09:03 dedmen

With wounding system rework merged I decided to finally have a look at this refactor, before doing anything I thought I'd first inspect everywhere we read the open wounds array in the codebase and count where it makes more sense to have constant time lookup by body part versus a flat structure to iterate:

  • Iteration: 2
  • Body part lookup: 9
  • Irrelevant: 4

With this in mind, I'd probably just use one level of hashmap to be able to quickly lookup the wounds on a given body part, then have the values be flat collections. I don't think we perform searches for specific wound types enough to warrant a second level of hashmaps.

kymckay avatar May 28 '22 23:05 kymckay

It's a shame SQF has no heap structure since then we could prioritise max wound bleeding for the bandaging logic without having to iterate.

kymckay avatar May 28 '22 23:05 kymckay