尝试使用 language-java-classfile 导入基本的 Java 运行库 rt.jar 后,发现它会占用大量内存。
我已将演示问题的程序缩减到 100 行,并上传到hpaste。如果不在第 94 行之前强制评估 stream
,我就没有机会运行它,因为它会耗尽我的所有内存。在传递给 getClass
之前强制执行 stream
可以完成,但仍会占用大量内存。
34,302,587,664 bytes allocated in the heap
32,583,990,728 bytes copied during GC
139,810,024 bytes maximum residency (398 sample(s))
29,142,240 bytes maximum slop
281 MB total memory in use (4 MB lost due to fragmentation)
Generation 0: 64992 collections, 0 parallel, 38.07s, 37.94s elapsed
Generation 1: 398 collections, 0 parallel, 25.87s, 27.78s elapsed
INIT time 0.01s ( 0.00s elapsed)
MUT time 37.22s ( 36.85s elapsed)
GC time 63.94s ( 65.72s elapsed)
RP time 0.00s ( 0.00s elapsed)
PROF time 13.00s ( 13.18s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 114.17s (115.76s elapsed)
%GC time 56.0% (56.8% elapsed)
Alloc rate 921,369,531 bytes per MUT second
Productivity 32.6% of total user, 32.2% of total elapsed
我以为问题在于ConstTable
一直存在,所以我也尝试在第94行强制使用cls
。但这只会使内存消耗和运行时间更糟:
34,300,700,520 bytes allocated in the heap
23,579,794,624 bytes copied during GC
487,798,904 bytes maximum residency (423 sample(s))
36,312,104 bytes maximum slop
554 MB total memory in use (10 MB lost due to fragmentation)
Generation 0: 64983 collections, 0 parallel, 71.19s, 71.48s elapsed
Generation 1: 423 collections, 0 parallel, 344.74s, 353.01s elapsed
INIT time 0.01s ( 0.00s elapsed)
MUT time 40.60s ( 42.38s elapsed)
GC time 415.93s (424.49s elapsed)
RP time 0.00s ( 0.00s elapsed)
PROF time 56.53s ( 57.71s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 513.07s (524.58s elapsed)
%GC time 81.1% (80.9% elapsed)
Alloc rate 844,636,801 bytes per MUT second
Productivity 7.9% of total user, 7.7% of total elapsed
我的问题基本上是,如何强制顺序处理涉及的文件,以便在处理完每个文件后,只有字符串结果 (cls
) 保留在内存中?
cereal
时遇到了两个问题:一是它似乎不支持按固定字节顺序的浮点数,另一个问题是缺少 MonadFix 实例。 - Cactus