ios - swift typecasting performance cost -


i trying keep func update:currenttime fast possible. function overridden skscene class , gets called around 2000 4000 times second. want loop through scene's children , optional typecast see if child implements observer interface , call update on that. note: make reference 2 separate func update methods here.

will performance shot if typecast 4000 times second? more importantly, how expensive typecast in swift?

code context:

// called inside func update:currenttime let children = self.children     child in children {         if let observer = child as? timerobserver {             observer.update()         }     } 

thanks!

it depends. casting e.g. int float cost compiler create real code convert 1 other.

in contrast object type cast @ no cost. it's method call fail cast type not tell should be. it's pretend object pointer point legal object. pointer not changed.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -