性能的object_setClass()而不是分配isa指针 [英] Performance of object_setClass() instead of assigning isa pointer

查看:326
本文介绍了性能的object_setClass()而不是分配isa指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在XCode(4.6)的最新更新中,我注意到有关JSONKit.m中几行的警告.具体而言,用于设置对象类的行:

I noticed with with the latest update to XCode (4.6), I was given a warning about a couple of lines in JSONKit.m. Specifically, lines that set the class of an object:

dictionary->isa = _JKDictionaryClass;

这些已标记为已弃用,并带有注释,说明首选方法是使用object_setClass():

These are marked as deprecated with a note that the preferred method was to use object_setClass():

object_setClass(dictionary, _JKDictionaryClass);

当我问为什么只希望沉默警告时,答案是:

When I asked why it was preferred to simply silence the warning, the response was:

即使新的Xcode版本抱怨,一切也都正常,我不想:
1)测试每个使用JSONKit的项目,以检查object_setClass()之后一切是否正常 2)宽松的cpu周期,这就是为什么我例如在NSJSONSerialization上使用JSONKit的原因.我当前的应用程序解析权重为600K-1M的json文件

Everything works fine even if new Xcode version complains, I don't want to :
1) test each project where i use JSONKit to check if everything goes fine after object_setClass()
2) loose cpu cycles, which is the reason why i use JSONKit over NSJSONSerialization for example. My current application parses json files that weights 600K-1M

我们在这里谈论多少性能方面的问题?

Just how much of a performance hit are we talking about here?

注意:

我更感兴趣

dictionary->isa = _JKDictionaryClassobject_setClass()

JSONKit vs NSJSONSerialization.

推荐答案

原因是函数调用总是有一些开销:参数应该被压入堆栈(以及调用方保存的寄存器),然后指令指针应该被压入堆栈.进行更新,然后在函数返回时以相反的方式进行所有操作.通常,与简单地取消引用指针相比,它在计算上要昂贵得多(它可以像mov [dest] [src]一样简单.

The reasoning is that function calls always have some overhead: the arguments should be pushed onto the stack (and caller-saved registers too), then the instruction pointer should be updated, then all this should be done in reverse when the function returns. It's generally more computationally expensive than simply dereferencing a pointer (which can be as simple as mov [dest] [src].

这篇关于性能的object_setClass()而不是分配isa指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆