Final remarks
结语
As we discussed in the introduction, optimization is a tricky business. There are several points to consider, starting with whether the program needs any optimization at all. If it has real performance problems, then we must focus on where and how to optimize it.
正如我们在介绍中讨论的,优化是件有技巧的事情。有几个要点需要考虑,从程序是否真的需要优化开始。如果确实有性能问题,我们必须关注在哪儿和怎样优化它。
----------------------- Page 14-----------------------28
The techniques we discussed here are neither the only nor the most important ones. We focused here on techniques that are peculiar to Lua, as there are several sources for more general techniques.
我们此处讨论的技术既不是唯一也不是最重要的。我们关注的是Lua独有的技术,因为存在一些针对更通用的技术的资料来源。
Before we finish, I would like to mention two options that are at the borderline of improving performance of Lua programs, as both involve changes outside the scope of the Lua code. The first one is to use LuaJIT, a Lua just-in-time compiler developed by Mike Pall. He has been doing a superb job and LuaJIT is probably the fastest JIT for a dynamic language nowadays. The drawbacks are that it runs only on x86 architectures and that you need a non-standard Lua interpreter (LuaJIT) to run your programs. The advantage is that you can run your program 5 times faster with no changes at all to the code.
在结束以前,我要说下两个处于模糊地带的提升Lua程序性能的选择,二者都涉及Lua代码范围之外的改变。第一个是使用LuaJIT,由Mike Pall开发的Lua即时编译器。他做了非常出色的工作,而且LuaJIT大概是现今最快的动态语言的即时编译器。缺点是它智能在x86架构上运行,并且你需要一个非标准的Lua解释器(LuaJIT)来运行你的程序。优点是你能以快于5倍的速度运行你得程序,一点也不用改变代码。
The second option is to move parts of your code to C. After all, one of Lua hallmarks is its ability to interface with C code. The important point in this case is to choose the correct level of granularity for the C code. On the one hand, if you move only very simple functions into C, the communication overhead between Lua and C may kill any gains from the improved performance of those functions. On the other hand, if you move too large functions into C, you loose flexibility.
第二个选择是把部分代码移到C中。毕竟,Lua的特点之一是与C代码结合的能力。在这种情况中的要点是为C代码选择正确的粒度级别。一方面,如果你只把非常简单的函数移到C中,Lua和C之间的通信开销可能消除那些函数带来的性能提升的收益。另一方面,如果你把太大的函数移到C中,就降低了灵活性。
Finally, keep in mind that those two options are somewhat incompatible. The more C code your program has, the less LuaJIT can optimize it.
最后,紧记那两个函数有点不相容。程序的C代码越多,LuaJIT能优化的越少。
阅读(1155) | 评论(0) | 转发(0) |