Flex AS3:较小的变量名称比较长的名称更快吗?

发布于 2024-09-02 02:26:49 字数 201 浏览 9 评论 0原文

我们正在优化 Flex AS3 应用程序。

我的一位团队成员建议我们缩小变量名称长度以优化应用程序性能。

即:

var IsRegionSelected:Boolean = false; //Slower
var IsRS:Boolean = false; //faster

这是真的吗?

We are in the process of the optimization of a Flex AS3 Application.

One of my team members suggested we make the variable name lengths smaller to optimize the application performance.

I.e.:

var IsRegionSelected:Boolean = false; //Slower
var IsRS:Boolean = false; //faster

Is this true?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

蓝色星空 2024-09-09 02:26:49

不,您获得的收益仅与 swf 的大小有关。

字符串被放入常量池中,引用该字符串的指令将使用索引。

它可以被视为(非常示意性):

常量池:

[0] IsRegionSelected
[1] IsRS

用法:

value at 0 = false
value at 1 = false

您的代码可能会被翻译为(对于局部变量):

push false
setlocal x

push false
setlocal y

其中x和y< /code> 是由编译器分配的寄存器 int,因此无论是 寄存器 2 还是寄存器 4 都没有区别。

有关更多详细信息,请阅读 avm 规范

No, the gain you will obtain will be only for the size of the swf.

String are put into a constant pool and instruction refering to this String will use an index.

it can be seen as (very schematic) :

constant pool:

[0] IsRegionSelected
[1] IsRS

usage:

value at 0 = false
value at 1 = false

Your code will be probably translated as (for local variable):

push false
setlocal x

push false
setlocal y

where x and y are register int assign by the compiler, so no difference if it's register 2 or register 4

For more detailed read the avm specification

戒ㄋ 2024-09-09 02:26:49

是的..我同意。更改名称长度不会对您有帮助。专注于项目渲染器、效果、状态和转换。这些可能会杀死你的资源。还要检查是否有任何嵌入图像、嵌入字体等,因为这些会增加您的最终 swf 文件大小并增加初始加载时间。

加油,PK

yep.. i second it. changing the name length is not gonna help you. concentrate on item renderers, effects, states and transitions. those may be killing your resource. also checkout for any embedding images, embedding fonts, etc, since those will increase ur final swf file size and increase initial loading time.

cheers, PK

暖阳 2024-09-09 02:26:49

我不这么认为,使用变量名的方式比它的长度更重要。

好的代码应该是一致的。无论这意味着为变量和函数的名称设置规则、采用标准方法,还是只是确保所有代码都以相同的方式缩进,一致性都会使您的代码更易于其他人阅读。

稍后人们应该解释一下你声明的变量名是什么。

var g:String;
var gang:String;

两者都执行相同的操作,其一是更具可读性,浏览您的代码的人也会解释它。

I don't think so, the way you use your variable name does matter than its length.

Good code should be consistent. Whether that means setting rules for the names of variables and functions, adopting standard approaches, or simply making sure all of your code is indented the same way, consistency makes your code easier for others to read.

One should later construe on what is your variable name declared.

var g:String;
var gang:String;

Both perform the same operation, one is more readability where someone going through your code will also construe it.

末蓝 2024-09-09 02:26:49

虽然性能提升非常小,但如果您打算稍后再次使用此应用程序,那么就不值得您保持理智。在此之前绝对可以进行任何其他优化 - 如果它确实慢到需要优化,那么在变量名称之前肯定需要首先考虑其他因素。

在诉诸 1-2 毫秒的增强之前,尽可能减少任何其他内容。

There's a very small performance gain, but if you plan to use this application again later, it's not worth your sanity. Do absolutely any other optimization you can before this one - and if it's really slow enough to need optimizing, then there are definitely other factors that you'll need to take care of first before variable names.

Cut anything else you can before resorting to 1-2 millisecond boosts.

死开点丶别碍眼 2024-09-09 02:26:49

正如 Matchu 所说,两者之间存在差异,但差异很小。

您应该考虑为变量分配有意义的 id,而不是仅仅使用没有意义的简单字符。

As Matchu says, there is a difference but a small one.

You should consider assigning meaningful ids to your variables instead of just using simple chars which have no sense.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文