harrycheung / Mobile-App-Performance

Source for this
https://medium.com/@harrycheung/cross-platform-mobile-performance-testing-d0454f5cd4e9
GNU General Public License v3.0
89 stars 26 forks source link

Hack point to be a struct. #7

Closed josephlord closed 9 years ago

josephlord commented 9 years ago

Brutal hack and no correctness checking done.

Don’t just merge this. PR is for showing code rather than immediate merging. I haven’t got the tests running and changing to a struct point type will have changed the semantics. It does however more than double the speed of the test on my iPhone 5 from about 28s to 13.5s on my iPhone 5 for 10000 runs.

If you want high performance in Swift then structs can really deliver and given more time I would have done a more extensive rewrite changing more of you classes into structs where it made sense. The code as it stands feels like a very direct translation that doesn't utilise the full strength of Swift and in particular structs.

harrycheung commented 9 years ago

Very interesting. Thanks for pointing this out. I'll finish the port. Would this apply to Objective-C?

josephlord commented 9 years ago

C type structs would be fast but don't have as good syntactic sugar as in Swift and aren't so idiomatic for Objective-C. Once you have abandoned objects it is essentially just C but that probably is the typical approach when really performance critical code is required.

harrycheung commented 9 years ago

Wow, performance is 100% better! Thanks for the tip.