220 likes | 349 Views
Experiments on the Effectiveness of an Automatic Insertion of Memory Reuses into ML-like Programs. Oukseh Lee (Hanyang University) Kwangkeun Yi (Seoul National University). *.
E N D
Experiments on the Effectiveness of an Automatic Insertion of Memory Reuses into ML-like Programs Oukseh Lee (Hanyang University) Kwangkeun Yi (Seoul National University)
* Oukseh Lee, Hongseok Yang, and Kwangkeun Yi. Inserting Safe Memory Reuse Commands into ML-like Programs. In Proceedings of the Annual International Static Analysis Symposium, volume 2694 of Lecture Notes in Computer Science, pp. 171-188, San Diego, California, June 2003. Question • Our SAS 2003 paper* presented • an algorithm to replaceallocations by memory reuse (or destructive update); and • some promising yet preliminary experiment numbers. • When and how much is it cost-effective? • Space & time-wise. • Before launching it inside our nML compiler.
l 1 2 3 4 4 1 2 3 5 result fun insert i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert i t in free l; h::z Example: insert insert 5 l 6 nil fun insert i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert i t in h::z
l result 5 fun insert i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert i t in free l; h::z Example: insert insert 5 l 1 1 2 2 3 3 4 4 6 nil fun insert i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert i t in h::z fun insert b i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert b i t in free l when b; h::z
L Analysis result usage =L.hd[L.tl X1 X1 L.hd L.tl L.hd X2 X2[ L Z X3 Z µ X3 [L.tl L.tl X4 X4[ Z [ X1[X2[L[X4[Z L.hd [ L.tl X =X1[ X2[ X3[ X4 µ X [ L L
Transformation [1/3] fun insert i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert i t in h::z fun insert b i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert i t in h::z When b=true, the transformed insert function deallocates the cons cells of the input list l excluding those of the result list.
Transformation [2/3] fun insert b i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert b i t in h::z b When is it safe to free the tail cells t not in the result z (L.tl\Z)?
Transformation [3/3] fun insert b i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert b i t in free l when ; h::z b When is it safe to free the head cell (L.hd)?
Analysis & Transformation Cost 1,500~29,000 lines/sec analysis & transformation cost (logarithmic scale) slope=1.46 program size (logarithmic scale)
Reuse Ratio 3.4%~93.9% of allocations are avoided. low reuse ratio due to much sharing.
Memory Peak Reduction 0.0%~71.9% peak reduction much reuse = much peak reduction memory peak reduction 41.9% 8.1% 84.4% 2.6% 10.6% 25.6% memory reuse ratio
Difference in Live Cells sieve 84.3% 56.5% merge 50.0% 49.4% qsort 93.9% 71.9% msort 89.3% 55.0%
Difference in Live Cells queens 4.2% 0.0% kb 3.4% 2.3% nucleic 16.9% 13.8% k-eval 31.5% 9.6%
Difference in Live Cells professor 41.9% 8.1% mirage 84.4% 2.6% life 10.6% 25.6%
GC Time & Runtime Changes -6.9%~90.5% GC-time reduction -7.3%~39.1% runtime reduction in Objective Caml system
50.0% 76.0% 24.0% 93.9% 63.2% 39.1% 89.3% 59.9% 21.6% High reuse ratio & big GC portion: runtime speedup 16.9% 52.1% 7.2% 50.0% 78.2% 30.0% 93.9% 57.2% 28.2% 89.3% 55.3% 20.7% 16.9% 46.3% 8.8% GC Time & Runtime Changes -6.9%~90.5% GC-time reduction -7.3%~39.1% runtime reduction in Objective Caml system
GC Time & Runtime Changes -6.9%~90.5% GC-time reduction -7.3%~39.1% runtime reduction 4.2% -6.8% -4.7% High reuse ratio & big GC portion: runtime speedup 3.4% -3.6% -7.3% Low reuse ratio: flags overhead 4.2% -8.4% -5.8% 3.4% -9.1% -6.7% in Objective Caml system
GC Time & Runtime Changes -6.9%~90.5% GC-time reduction -7.3%~39.1% runtime reduction 7.2% -5.5% 5.6% -2.6% High reuse ratio & big GC portion: runtime speedup 1.4% -3.8% 1.9% -2.9% Low reuse ratio: flags overhead 4.3% 4.8% Small GC portion: almost no effect 4.2% 0.1% 1.1% -0.9% 1.3% 0.6% in Objective Caml system
GC-time & Runtime Changes much reuse = much GC-time reduction much reuse & big GC-time portion = much runtime reduction GC time reduction runtime reduction memory reuse ratio GC portion x memory reuse ratio
memory peak reduction & GC time speedup high reuse ratio runtime speedup Conclusion transformation result program performance program not much sharing + big GC-time portion