English 中文(简体)
谷歌封闭器是否不断减少性能?
原标题:Does Google Closure Compiler ever decrease performance?

页: 1 由于 Java的文字文件装上软磁盘,其大小几乎只是问题。

我先是利用谷歌压缩机,因为它显然能够使业绩优化和缩小编码规模。

但是,我注意到,这是我从关闭汇编中得出的产出的顶点:

var i = true, m = null, r = false;

这一点显然是为了减少档案(随后所有使用true/null/>>。 整个文字可以用单一特性取代。

但这肯定会稍有影响? 它必须更快地读到字面上的true。 关键词比按名称对变数进行研究,并确定其价值是true<>/code>?

这一业绩是否值得担心? 谷歌封闭公司是否真的会延缓执行?

最佳回答

The answer is maybe.

Lets look at what the closure team says about it.

From the FAQ:

Does the compiler make any trade-off between my application s execution speed and download code size?

Yes. Any optimizing compiler makes trade-offs. Some size optimizations do introduce small speed overheads. However, the Closure Compiler s developers have been careful not to introduce significant additional runtime. Some of the compiler s optimizations even decrease runtime (see next question).

Does the compiler optimize for speed?

In most cases smaller code is faster code, since download time is usually the most important speed factor in web applications. Optimizations that reduce redundancies speed up the run time of code as well.

我完全质疑他们在这里提出的第一个假设。 所用名称的大小并不直接影响到 Java的各种发动机如何对待代码-事实上,如果你称之为<条码>、代相传的密码>、<条码>或<条码>x(但我作为方案管理员确信这样做)。 下载时间是最重要的部分,如果你重新担心交付——如果操作缓慢的文字可能是由我怀疑工具根本无法说明的数百万件事情造成的。

To truthfully understand why your question is maybe, first thing you need to ask is "What makes JavaScript fast or slow?"

Then of course we run into the question, "What JavaScript engine are we talking about?"

我们:

  • Carakan (Opera)
  • Chakra (IE9+)
  • SpiderMonkey (Mozilla/FireFox)
  • SquirrelFish (Apple s webkit)
  • V8 (Chrome)
  • Futhark (Opera)
  • JScript (All versions of IE before 9)
  • JavaScriptCore (Konqueror, Safari)
  • I ve skipped out on a few.

是否有任何人真的认为他们都这样做? 特别是J.S.和V8? Heck no!

So again, when google closure compiles code, which engine is it building stuff for? Are you feeling lucky?

奥凯,由于我们永远无法涵盖所有这些基地,我们就试图在这里更全面地看一看“旧”和“新”法典。

Here s a quick summary for this specific part from one of the best presentations on JS Engines I ve ever seen.

Older JS engines

  • Code is interpreted and compiled directly to byte code
  • No optimization: you get what you get
  • Code is hard to run fast because of the loosely typed language

New JS Engines

  • Introduce Just-In-Time(JIT) compilers for fast execution
  • Introduce type-optimizing JIT compilers for really fast code (think near C code speeds)

这里的主要区别是,新的发动机引进了联合技术汇编者。

从本质上讲,国际投资协议将优化执行,使其能够更快地运行,但如果它像以前那样做的事情,它就会转而走,并再次放慢。

You can do such things by having two functions like this:

var FunctionForIntegersOnly = function(int1, int2){
    return int1 + int2;
}

var FunctionForStringsOnly = function(str1, str2){
    return str1 + str2;
}

alert(FunctionForIntegersOnly(1, 2) + FunctionForStringsOnly("a", "b"));

坚持道道关闭实际上使整个法典简化为:

alert("3ab");

该书的每个衡量标准都比较快。 这里确实发生的情况是,它简化了我真正简单的榜样,因为它确实是部分执行。 然而,这就是你们需要小心的领域。

让我们说,我们的《法典》中有一个综合工具,汇编者把它变成了这样的内容:

(function(a) {
 return function(b) {
    return a(a)(b)
  }
})(function(a) {
  return function(b) {
    if(b > 0) {
      return console.log(b), a(a)(b - 1)
    }
  }
})(5);

守则没有真正更快,只是简单明了。

JIT would normally see that in practice your code only ever takes two string inputs to that function, and returns a string (or integer for the first function), and this put it into the type-specific JIT, which makes it really quick. Now, if google closure does something strange like transform both those functions that have nearly identical signatures into one function (for code that is non-trivial) you may lose JIT speed if the compiler does something JIT doesn t like.

So, what did we learn?

  • You might have JIT-optimized code, but the compiler re-organizes your code into something else
  • Old browsers don t have JIT but still run your code
  • Closure compiled JS invokes less function calls by doing partial-execution of your code for simple functions.

So what do you do?

  • Write small and to-the-point functions, the compiler will be able to deal with them better
  • If you have a very deep understanding of JIT, hand optimizing code, and used that knowledge then closure compiler may not be worthwhile to use.
  • If you want the code to run a bit faster on older browsers, it s an excellent tool
  • Trade-offs are generally worth-while, but just be careful to check things over and not blindly trust it all the time.

总的来说,你的法典较快。 您可以介绍各种联合技术汇编者不喜欢的东西,但是,如果你的法典使用较小的职能,纠正偏袒目的的假想,他们会再少见。 如果您想到汇编者所从事工作的全部范围(可下载和更快执行),那么,如<代码>var i = 真实性,m = 无效;可能是汇编者即使工作较慢所做的一次值得一提的贸易,总寿命则会更快。

值得注意的是,在网上执行中最常见的瓶颈是文件目标模式,我建议,如果你的守则是缓慢的话,你将作出更大的努力。

问题回答

看来,在使用字面<代码>true<>/code>或null或变式的现代浏览器中,绝对没有任何区别(如0;完全相同)。 在极少数情况下,变量实际上较快。

因此,这些储蓄的外派价值是值得的,没有代价。

:

“true

:

“null

我认为,将判处非常轻微的罚款,但不太可能在较新的现代浏览器中占据很大比例。

发出封闭装置的标准别要素是所有全球变量的通知。 这就意味着,在 Java本发动机需要直线时间去浏览功能范围(如IE <9)的旧浏览器中,越权越权越权,就越需要找到“真实”或“假”等变量。 几乎所有现代的 Java原发动机都优化了全球可变的获取,因此,在许多情况下,这种处罚不应再维持。

此外,除了派任或争辩外,确实有不少地方在编纂法典中看到“真实”或“真实”或“死亡”。 例如,if (someFlag ==真实) ..., 大部分只是书面的if (someFlag) ......, 汇编者将其汇编成a && ...。 你们大多只见到他们的任务(someFlag = real;)和论点(someFunc(true);),这些事实并不经常发生。

结论是:虽然许多人怀疑关闭竞争主管机构的标准内容(包括专题)是否有用,但你却不期望任何物质业绩受到打击。 不过,你也期望在预计规模上产生任何物质效益。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.