Generic Typing Policy Impacts on Program Performances Alexandre - - PowerPoint PPT Presentation

generic typing policy impacts on program performances
SMART_READER_LITE
LIVE PREVIEW

Generic Typing Policy Impacts on Program Performances Alexandre - - PowerPoint PPT Presentation

Policies Problem Micro-benchmarks Comparison in Nit Conclusion Generic Typing Policy Impacts on Program Performances Alexandre Terrasa Jean Privat Universit du Qubec Montral ICOOOLPS13 201372 Montpellier Generic


slide-1
SLIDE 1

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Generic Typing Policy Impacts

  • n Program Performances

Alexandre Terrasa — Jean Privat

Université du Québec à Montréal

ICOOOLPS’13 2013–7–2 Montpellier

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 1/28

slide-2
SLIDE 2

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 2/28

slide-3
SLIDE 3

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 3/28

slide-4
SLIDE 4

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Invariant policy

Invariant policy: C++ Object List<Object> List<Fruit> FruitSkewer<Fruit> List<Banana> FruitSkewer<Banana> ∀A, B, GA, GB : GA <: GB ⇔ A = B

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 4/28

slide-5
SLIDE 5

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Covariant policy

Covariant policy: Eiffel, C#, Nit Object List<Object> List<Fruit> FruitSkewer<Fruit> List<Banana> FruitSkewer<Banana> ∀A, B, GA, GB : GA <: GB ⇔ A <: B

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 5/28

slide-6
SLIDE 6

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Erased policy

Erased policy: Java, Scala Object List FruitSkewer ∀GA, GB : GA <: GB

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 6/28

slide-7
SLIDE 7

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 7/28

slide-8
SLIDE 8

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 8/28

slide-9
SLIDE 9

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 9/28

slide-10
SLIDE 10

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 10/28

slide-11
SLIDE 11

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 11/28

slide-12
SLIDE 12

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 12/28

slide-13
SLIDE 13

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 13/28

slide-14
SLIDE 14

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

  • riented language with static typing

multiple inheritance virtual and nullable types generics following a covariant policy (per spec.)

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 14/28

slide-15
SLIDE 15

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Micro-benchmarks

Objectives check that Nit performances are reasonable

  • bserve 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.)

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 15/28

slide-16
SLIDE 16

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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 16/28

slide-17
SLIDE 17

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) {} 6 else { x = x - i + j; a = b;} 7 } 8 } 9 System.out.println(x); 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

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 17/28

slide-18
SLIDE 18

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Execution time of programs on the raw loop

0.5 1 1.5 2 2.5 T emps (s) g++ clang++ java gcj scala gmcs es se nitg nitg-s

TYPE_TEST is true

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 18/28

slide-19
SLIDE 19

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Variations on the depth of the type hierarchy

R :> C1R :> C2R :> · · · :> ChR

20 40 60 80 100 120 2 4 8 T emps (s) g++ clang++ java gcj scala gmcs es se nitg nitg-s

TYPE_TEST is a successful subtype test C++ is ≈ 200s for depth=4 and ≈ 300s for depth=8

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 19/28

slide-20
SLIDE 20

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Failed subtype test

20 40 60 80 100 120 2 4 8 T emps (s) g++ clang++ java gcj scala gmcs es se nitg nitg-s

TYPE_TEST is the negation of a failed subtype test C++ is ≈ 250s for depth=4 and ≈ 300s for depth=8

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 20/28

slide-21
SLIDE 21

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Generic covariant subtype test

R :> C1C1R :> C1C2R :> · · · :> C1ChR

5 10 15 20 25 30 35 2 4 8 T emps (s) gmcs es se nitg nitg-s

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 21/28

slide-22
SLIDE 22

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Nested generic types in subtype test

R :> C1R :> C1C1R :> · · · :> C1C1C1 · · ·

5 10 15 20 25 30 35 2 4 8 T emps (s) gmcs es se nitg nitg-s

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 22/28

slide-23
SLIDE 23

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Discussion

Constance in time hierarchy depth impacts g++, clang++ and EiffelStudio nesting level impacts EiffelStudio successful vs. failed tests impacts java Performance Nit implementations are good calling (complex) functions for type test is inefficient Policies Nothing conclusive

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 23/28

slide-24
SLIDE 24

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Policies comparison in Nit

4 compiler variants for Nit nitg-s implements covariant policy nitg-e implements erased policy nitg-su and nitg-eu are unsafe variations: no checks are done at runtime Corpus : 5 real Nit programs nitg the new Nit compiler (2 distinct execution runs) nit the naive Nit interpreter shoot an old-school 2D soot-them-up (headless version) bintree Boehm’s bintree benchmark w/ generics pep8analysis static analyzer on Pep/8 programs

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 24/28

slide-25
SLIDE 25

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Performances considering generics policies in Nit

2 4 6 8 10 12 nitg nitg-s nit shoot bintrees pep8analysis T emps (s) nitg-s nitg-e nitg-su nitg-eu

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 25/28

slide-26
SLIDE 26

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Discussion

Typing policies: covariance vs. erased Performances are quite comparable nitg-e produces often faster programs than nitg-s but only with a maximum of 5.8% with nit Checks at runtime : safe vs. unsafe policies Performances are also quite comparable subtype tests required by policy do not represent a significant

  • verhead
  • nly with a maximum of 9.1% with bintrees
  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 26/28

slide-27
SLIDE 27

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Conclusion

Impacts on performances of the generics typing policies 4 near-identical compilers for the Nit language similar performances with existing solutions compared on a corpus of reals programs written in Nit Our Conclusion covariant typing policy implies an insignificant performance

  • verhead

the choice of a generics typing policy by a language designer should not be done on performances considerations

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 27/28

slide-28
SLIDE 28

Policies Problem Micro-benchmarks Comparison in Nit Conclusion

Questions

Thank you for your attention

Any questions ?

  • A. Terrasa & J. Privat

Generic Typing Policy Impacts on Program Performances 28/28