Policies Problem Micro-benchmarks Comparison in Nit Conclusion Generic Typing Policy Impacts on Program Performances Alexandre Terrasa — Jean Privat Université du Québec à Montréal ICOOOLPS’13 2013–7–2 Montpellier Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 1/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Summary 1 Generic typing policies 2 Problem: Comparing generic typing policies 3 Micro-benchmarks 4 Policies comparison in Nit 5 Conclusion Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 2/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Generic typing policies Generic typing policies rules regarding formal types and generic classes relationships between generic types type verifications made at runtime 3 common policies invariant covariant (and other *-variants) erased Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 3/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Invariant policy Invariant policy : C++ Object List<Object> List<Fruit> List<Banana> FruitSkewer<Fruit> FruitSkewer<Banana> ∀ A , B , G � A � , G � B � : G � A � < : G � B � ⇔ A = B Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 4/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Covariant policy Covariant policy : Eiffel, C#, Nit Object List<Object> List<Fruit> List<Banana> FruitSkewer<Fruit> FruitSkewer<Banana> ∀ A , B , G � A � , G � B � : G � A � < : G � B � ⇔ A < : B Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 5/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Erased policy Erased policy : Java, Scala Object List FruitSkewer ∀ G � A � , G � B � : G � A � < : G � B � Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 6/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Example of a statically correct program with each policy 1 List <Fruit > lf; 2 List <Banana > lb = new List <Banana >; 3 Object o = lb; 4 5 lf = (List <Fruit >)o; 6 7 lf.push(new Coconut ()); 8 9 Banana b = lb.pop (); 10 11 b.peel (); 12 This program is statically correct with the three policies But the dynamic behaviors differ Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 7/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Example of a statically correct program with each policy 1 List <Fruit > lf; 2 List <Banana > lb = new List <Banana >; 3 Object o = lb; 4 5 lf = (List <Fruit >)o; 6 ↑ Invariance: Expected ‘List<Fruit>‘, got ‘List<Banana>‘ 7 lf.push(new Coconut ()); 8 9 Banana b = lb.pop (); 10 11 b.peel (); 12 This program is statically correct with the three policies But the dynamic behaviors differ Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 8/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Example of a statically correct program with each policy 1 List <Fruit > lf; 2 List <Banana > lb = new List <Banana >; 3 Object o = lb; 4 5 lf = (List <Fruit >)o; 6 7 lf.push(new Coconut ()); 8 ↑ Covariance: Expected a ‘Banana‘, got a ‘Coconut‘ 9 Banana b = lb.pop (); 10 11 b.peel (); 12 This program is statically correct with the three policies But the dynamic behaviors differ Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 9/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Example of a statically correct program with each policy 1 List <Fruit > lf; 2 List <Banana > lb = new List <Banana >; 3 Object o = lb; 4 5 lf = (List <Fruit >)o; 6 7 lf.push(new Coconut ()); 8 9 Banana b = lb.pop (); 10 ↑ Erased: Expected a ‘Banana‘, got a ‘Coconut‘ 11 b.peel (); 12 This program is statically correct with the three policies But the dynamic behaviors differ Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 10/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Example of a statically correct program with each policy 1 List <Fruit > lf; 2 List <Banana > lb = new List <Banana >; 3 Object o = lb; 4 5 lf = (List <Fruit >)o; 6 7 lf.push(new Coconut ()); 8 9 Banana b = lb.pop (); 10 11 b.peel (); 12 ↑ Dynamic: no method ‘peel‘ on ‘Coconut‘ This program is statically correct with the three policies But the dynamic behaviors differ Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 11/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Comparing generic typing policies What is the impact of these policies on program performances? Comparing generic typing policies: a difficult task changing the policy = changing the language semantic need to find valid programs with each policy need to find compilers for each policy compared compilers must (idealy) only differs on the policy Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 12/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Comparing generic typing policies What is the impact of these policies on program performances? Comparing generic typing policies: a difficult task changing the policy = changing the language semantic need to find valid programs with each policy need to find compilers for each policy compared compilers must (idealy) only differs on the policy We are lucky Most Nit programs have the same behavior with either the erased or the covariant policy Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 13/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion The Nit language Nit — http://nitlanguage.org an evolution of PRM dedicated to exhaustive assessments of various implementation techniques and compilation schemes Some Features oriented language with static typing multiple inheritance virtual and nullable types generics following a covariant policy (per spec.) Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 14/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Micro-benchmarks Objectives check that Nit performances are reasonable observe behaviors across a variety of implementations What will vary? generic typing policies compilation scheme (global, separated, etc.) generics impelentation thenique (homogenous, heterogenous, etc.) OO implementation technique (binary matric, coloring, binary trees, etc.) Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 15/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Micro-benchmarks Policies, Languages and Engines Invariant C++: g++ & clang++ Covariant C#: gmcs + mono Eiffel: Eiffel Studio ( es ) & SmartEiffel ( se ) Nit: nitg & nitg-s Erased Java: javac + icedtea & gcj Scala: scalac + icedtea Corpus Short programs that loops a lot around some type tests Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 16/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Micro-benchmark code in Java 1 static public void test(Root a, Root b, int loops , int start) { 2 int x = start; 3 for(int i = 0; i < loops; i++) { 4 for(int j = 0; j < loops; j++) { 5 if(TYPE_TEST && x >= 0) {} else { x = x - i + j; a = b;} 6 } 7 } 8 System.out.println(x); 9 10 } two for loops of 50.000 iterations ⇒ 2.5G iterations the else part is dead code (avoid loop optimizations) 6 consecutive executions the first is discarded keep minimum, maximum, and average user time Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 17/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Execution time of programs on the raw loop 2.5 g++ clang++ 2 java gcj scala emps (s) 1.5 gmcs es se 1 nitg T nitg-s 0.5 0 TYPE_TEST is true Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 18/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Variations on the depth of the type hierarchy R : > C 1 � R � : > C 2 � R � : > · · · : > C h � R � 120 g++ clang++ 100 java gcj 80 scala emps (s) gmcs es 60 se nitg T 40 nitg-s 20 0 2 4 8 TYPE_TEST is a successful subtype test C++ is ≈ 200s for depth=4 and ≈ 300s for depth=8 Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 19/28
Policies Problem Micro-benchmarks Comparison in Nit Conclusion Failed subtype test 120 g++ clang++ 100 java gcj 80 scala emps (s) gmcs es 60 se nitg T 40 nitg-s 20 0 2 4 8 TYPE_TEST is the negation of a failed subtype test C++ is ≈ 250s for depth=4 and ≈ 300s for depth=8 Generic Typing Policy Impacts on Program Performances A. Terrasa & J. Privat 20/28
Recommend
More recommend