在 JVM 中分配大的 PermGen 空间时,Scala 中的 First-class 函数会成为问题吗?
关于Scala中的一等函数,在Programming by Scala一书中是这么写的:
函数文字被编译成 实例化时的类 运行时是一个函数值。
当程序中使用很多first-class函数时,会影响JVM的PermGen空间吗?因为编译器不是为函数值的每个变体生成类,而是为函数值的每个变体生成类(例如,在部分应用函数的不同定义的情况下)。
Regarding first-class functions in Scala, it is written in the book Programming by Scala:
A function literal is compiled into a
class that when instantiated at
run-time is a function value.
When there will be many first-class functions used in a program, will this affect the JVM's PermGen space? because instead of simple functions the compiler is generating classes for each variation of the function value (e.g. in the case of varied definitions of partially applied functions).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尽管您可以调整 JVM 上的几乎任何内存参数,但内存配置文件肯定会与普通 Java 程序不同。
然而,我只能说,在深入参与 Scala 社区的一年里,我从未见过有人抱怨这一点。
The memory profile is certainly going to be different than that of normal Java programs, though you can tune pretty much any memory parameter on the JVM.
All I can say, however, is that in one year of deep involvement in the Scala community, I have never seen anyone complain about this.
我没有证据证明这一点,但我的感觉是,如果您正在编写任何重要的程序,那么程序的“真实”数据占用的空间量将大大使一些程序占用的空间量相形见绌。额外的函数即类定义。
换句话说,我不会为此担心。
I don't have substantiation for this, but my feeling is that if you're writing any non-trivial program, the amount of space taken up for your program's "real" data will vastly dwarf the amount of space taken up by a few extra function-as-class definitions.
In other words, I wouldn't worry about it.
一个经过验证的数学事实是,使用一流函数生成的类的数量将能够渐近地接近(但永远不会超过)完整 Spring 发行版中已编译类的数量。别担心,那些先驱者将首先解决永久问题!
It is a proven mathematical fact that the number of classes you generate with first-class functions will be able to asymptotically approach, but never surpass, the number of compiled classes in the full Spring distribution. Don't worry, those pioneers will deal with the permgen issues first!