0

let me start off by showing that I have this UIImageView set up in my ViewController:

enter image description here

Each one of the lines contains a UIButton for a body part. If I select a particular button, it will segue me appropriately.

What'd I like to do is, when the user taps (but doesn't release) the button, I'd like the appropriate body part to show like this:

enter image description here

I can achieve this using 2 options:

  1. UIBuzierPath class to draw, but would take a lot of trial and error and many overlapping shapes per body part to get fitting nicely as similiar in a previous question: Create clickable body diagram with Swift (iOS)
  2. Crop out the highlighted body parts from the original image and position it over the UIImageView depending on which UIButton selected. However there would only be one image per body part, but still less cumbersome then option 1.

Now, my question is not HOW to do it, but which would be a BETTER option for achieving this in terms of cpu processing and memory allocation?

In other words, I'm just concerned about my app lagging as well as taking up app size storage. I'm not concerned about how much time it takes to do it, I want to just make sure my app doesn't stutter when it tries to draw all the shapes.

Thanks.

Community
  • 1
  • 1
Pangu
  • 3,721
  • 11
  • 53
  • 120
  • I know it isn't Swift, but you could always make the diagram in html and load that into a WebView. That wouldn't take barely any CPU! – brimstone May 04 '16 at 21:40

2 Answers2

3

It is very very very unlikely that either of those approaches would have any significant impact on CPU or memory. Particularly if in option 2, you just use the alpha channels of the cutout images and make them semitransparent tinted overlays. CPU/GPU-wise, neither of the approaches would drop you below the max screen refresh rate of 60fps (which is how users would notice a performance problem). Memory-wise, loading a dozen bezier paths or single-channel images into RAM should be a drop in the bucket compared to what you have available, particularly on any iOS device released in the last 5 years unless it's the Apple Watch.

Keep in mind that "premature optimization is the root of all evil". Unless you have seen performance issues or have good reason to believe they would exist, your time is probably better spent on other concerns like making the code more readable, concise, reusable, etc. See this brief section in Wikipedia on "When to Optimize": https://en.wikipedia.org/wiki/Program_optimization#When_to_optimize

Daniel Hall
  • 13,457
  • 4
  • 41
  • 37
1

Xcode have tests functionality built in(and performance tests too), so the best way is to try both methods for one body part and compare the results.

You may find the second method to be a bit slower, but not enough to be noticed by the user and at the same time a lot more easier to implement.

For quick start on tests here.

Performance tests here.

anakin
  • 551
  • 4
  • 12