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
Post a Comment