如何减少Scala(/ Java)启动开销?

编程入门 行业动态 更新时间:2024-10-11 07:31:05
本文介绍了如何减少Scala(/ Java)启动开销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对Java世界一无所知(我主要使用C / Python)但Scala看起来很有趣,可以吸引我。我遇到的一个问题是巨大的启动开销 - 最少0.3秒,更多如果我使用解释器而不是编译,相比之下,对于Python或C实际上是0。因此,即使语言比Python快几十倍,如果我试图将它用于简单的任务,它仍然是在实践中要慢得多。

有没有办法减少这个时间,或者它是JVM中不可避免的一部分+ Scala所需(隐式)导入的数量程序?

解决方案

你在使用什么类型的计算机?显然存在JVM启动开销,但如果JVM检测到您正在运行服务器级机器。

在J2SE平台5.0版中,一类称为服务器级机器的机器被定义为具有以下内容的机器: p>

  • 2个或更多物理处理器
  • 2个或更多GB物理内存

您可以使用 -client将JVM置于客户端模式 选项。调整客户端模式以缩短启动时间。

还有转向 模块化JVM (项目 Jigsaw )这将进一步缩短启动时间 - 这已经从 JDK 1.6.0_10 开始。

I'm pretty ignorant of the Java world (I do mostly C / Python) but Scala looked interesting enough to pull me in. One problem I'm having with it is the enormous startup overhead - 0.3 seconds minimum, much more if I'm using the interpreter instead of compiling, compared to effectively 0 for Python or C. So even though the language is tens of times faster than Python once it gets going, if I'm trying to use it for simple tasks it's still considerably slower in practice.

Is there any way to reduce this time, or is it an unavoidable part of the JVM + the number of required (implicit) imports for a Scala program?

解决方案

What sort of computer are you using it on? Obviously there is a JVM startup overhead but this is even greater if the JVM detects you are running on a server-class machine.

In the J2SE platform version 5.0 a class of machine referred to as a server-class machine has been defined as a machine with:

  • 2 or more physical processors
  • 2 or more Gbytes of physical memory

You can put the JVM in client mode by using the -client option. The client mode is tuned for fast startup time.

There is also the move to modularize the JVM (project Jigsaw) which will improve startup times even more - this has started with JDK 1.6.0_10.

更多推荐

如何减少Scala(/ Java)启动开销?

本文发布于:2023-11-25 20:28:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631235.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:开销   Scala   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!