Upgrade to Pro — share decks privately, control downloads, hide ads and more …

実行時におけるJVMバイトコード最適化手法

 実行時におけるJVMバイトコード最適化手法

todesking

March 26, 2016
Tweet

More Decks by todesking

Other Decks in Technology

Transcript

  1. ࣮ߦ࣌ʹ͓͚Δ
    +7.όΠτίʔυ
    ࠷దԽٕ๏
    todesking@maverick

    View full-size slide


  2. w !UPEFTLJOHGSPN.BWFSJDL JOD
    w 7JNͰ4DBMBΛॻ͍͍ͯΔ
    w 8FC޿ࠂܥͷ࢓ࣄΛ͍ͯ͠·͕͢ɺओʹ1%'ͷϨ
    ϯμϦϯάΤϯδϯͳͲΛ࡞͍ͬͯΔ

    View full-size slide

  3. ͋Β͢͡
    w 4DBMB͸ߴ౓ͳந৅ԽػೳΛ࣋ͭ
    w ந৅Խ͸ΦʔόϔουΛ൐͏
    w ಛఆͷ৚݅Ͱ͸ɺ͜ͷΦʔόϔου͕க໋త
    w ࣮ߦ࣌ʹόΠτίʔυॻ͖׵͑ͯ͸΍͘͢Δ΍ͭΛ
    ͭͬͨ͘

    View full-size slide

  4. $IBQUFS
    4DBMB͸ศར

    View full-size slide

  5. 4DBMBͷ
    ͞·͟·ͳந৅Խػߏ
    w Ϋϥε
    w USBJUʹΑΔNJYJO
    w VOBQQMZʹΑΔΧελϚΠζՄೳͳύλʔϯϚο
    ν
    w ܕΫϥε
    w *NQMJDJUDPOWFSTJPO
    w ϑΝʔετΫϥεͳؔ਺

    View full-size slide

  6. 4DBMBͷಛੑ
    w 001ͱ'1ͷػೳ͕࢖͑Δ
    w খ͞ͳ൚༻෦඼Λ૊Έ߹Θͤͯ࠶ར༻͢Δͷ͕༰қ
    ʹ

    View full-size slide

  7. $IBQUFSಈػ

    View full-size slide

  8. 4DBMB.BUTVSJ

    View full-size slide

  9. ͳͷͰ
    ͜͜Ͱ
    ൃද͠·͢

    View full-size slide

  10. ϞδϡϥʔγϯηαΠβʔ
    Photo by Nina Richards https://commons.wikimedia.org/wiki/File:Doepfer_A-100.jpg

    View full-size slide

  11. ԿΛ͍͔ͨ͠
    w ϞδϡϥʔγϯηൃৼثɺϑΟϧλͳͲͷجຊత
    ͳϞδϡʔϧΛଟ਺૊Έ߹ΘͤͯԻΛ࡞Δγϯηα
    Πβʔ
    w 4DBMBͰϞδϡϥʔͳγϯηΛͭ͘Γ͍ͨ

    View full-size slide

  12. දݱ͍ͨ͠ཁૉ
    7$0 7$'
    -'0
    +
    z-1
    Ϟδϡʔϧؒͷ઀ଓ
    ৴߸ॲཧͷ಺༰

    View full-size slide

  13. දݱ͍ͨ͠ཁૉ
    w ͜ΕΒͷجຊཁૉͰදݱͰ͖
    Δ
    w ઀ଓ
    w ෼഑
    w ߹ྲྀ
    w ϧʔϓ
    w 4DBMBͰͲ͏ॻ͘

    View full-size slide

  14. "SSPX
    w ܕΫϥεͷͻͱͭ
    w 'VODUJPOBM3FBDUJWF1SPHSBNNJOHͰΑ͘
    ࢖ΘΕͯΔ
    https://wiki.haskell.org/Yampa

    View full-size slide

  15. "SSPXʹΑΔදݱ
    +
    z-1
    val z_1 = init(0.0)
    val plus = arr { case (a, b) => a + b }
    val out =
    in >>> (z_1 &&& id) >>> plus

    View full-size slide

  16. "SSPXʹΑΔදݱ
    +
    z-1
    val z_1 = init(0.0)
    val plus = arr { case (a, b) => a + b }
    val out =
    in >>> (z_1 &&& id) >>>
    (plus *** (arr(_._1) >>> z_1)) >>> plus
    +
    z-1
    (´ŋ_ŋ`)???

    View full-size slide

  17. "SSPXه๏
    w 4DBMBʹ͓͍ͯɺϞφυ͸GPS
    DPNQSFIFOTJPOͰॻ͚Δ
    w "SSPX΋γϯλΫεγϡΨʔͰॻ͖͍ͨ
    w )BTLFMMʹ͸"SSPX༻ͷγϯλΫεγϡΨʔͰ
    ͋ΔQSPDه๏͕͋Δ
    w 4DBMBͰ΋΍Γ͍ͨʂ΍Γ·ͨ͠ʂ
    w HJUIVCUPEFTLJOHBSSPX@CVJMEFSTDBMB

    View full-size slide

  18. "SSPXʹΑΔදݱ
    XJUITZOUBYTVHBS
    +
    z-1
    val z_1 = init(0.0)
    val plus = arr { case (a, b) => a + b }
    val out =
    for {
    a <- z_1 -< in
    b <- plus -< (in, a)
    c <- z_1 -< a
    d <- plus -< (b, c)
    } yield d
    +
    z-1
    ʋ(´ʔʆ)ϊಡΊΔಡΊΔ
    a
    b
    c d
    in

    View full-size slide

  19. "SSPXʹΑΔ
    ৴߸ॲཧͷ࣮૷

    ؔ਺߹੒ͷଟ༻

    View full-size slide

  20. "SSPXʹΑΓ
    ߏஙͨ͠
    ৴߸ॲཧϑϩʔͷྫ
    w ؙ͍ͷ͕ؔ਺ɺ
    ໼ҹ͕߹੒
    w ӈ൒෼Ҏ্Λ
    ઎ΊͯΔͷ͕
    جຊతͳϞ
    δϡʔϧͷͻ
    ͱͭɺ7$'
    w Ϟδϡʔϧ;
    ͨͭܨ͍ͩͩ
    ͚Ͱ͜Ε

    View full-size slide

  21. ໰୊͸Φʔόʔϔου
    w ओཁͳॲཧͱൺֱͯؔ͠਺߹੒ͱUVQMJOHͷ਺͕๲

    w ϦΞϧλΠϜͰԻ੠ग़ྗ͍ͨ͠ͷͰɺ͜ͷΦϒδΣ
    ΫτάϥϑΛLճTFD΄ͲධՁ͢Δඞཁ͕͋
    Δ
    w ͍͘ΒϝϞϦ֬อ΍ؔ਺ݺͼग़͠ͷίετ͕௿͍ͱ
    ݴͬͯ΋ɺͪΐͬͱ͜Ε͸

    View full-size slide

  22. ந৅Խʹ͸ϦεΫ͕͋Δ
    w ύϑΥʔϚϯεΦʔόϔου
    w ଟ͘ͷ৔߹͸ɺ࣮༻্໰୊ʹͳΒͳ͍
    w ໰୊ʹͳΔ৔߹͸ɺϗοτεϙοτͷΈ࠷దԽ͢Ε
    ͹Α͍
    w ͔͠͠ɺϗοτεϙοτ͕දݱ͍ͨ͠υϝΠϯͦͷ
    ΋ͷͩͬͨ৔߹͸ʁ
    w ந৅ԽΛࣺͯͯϕλॻ͖͢Δ͔͠ͳ͍ͷ͔

    View full-size slide

  23. $IBQUFSΦʔό
    ϔου܏޲ͱରࡦ

    View full-size slide

  24. ؔ਺߹੒Ͱൃੜ͢Δ
    Φʔόϔου
    w ෆ༻ͳΠϯελϯεͷੜ੒ #PYJOH5VQMJOH

    w ෆ༻ͳϝιουݺͼग़͠
    w ্هʹΑΔɺ࠷దԽػձͷݮগ

    View full-size slide

  25. طଘͷ࠷దԽख๏
    w 4DBMBίϯύΠϥ͕͓͜ͳ͏࠷దԽ
    w +7.ͷ+*5ίϯύΠϥʹΑΔ࠷దԽ

    View full-size slide

  26. #PYJOH5VQMJOH
    w (FOFSJDͳؔ਺ͷҾ਺͸࣮࣭0CKFDU
    w ϓϦϛςΟϒܕΛ౉͍ͨ͠৔߹͸#PYJOHൃੜ
    • Integer.valueOf(n)
    w ෳ਺ͷ஋Λฦ͍ͨ͠৔߹͸5VQMFΛ࡞Δඞཁ͕͋
    Δ
    w ϝϞϦ֬อͷίετɺ($ͷίετ͕ൃੜ

    View full-size slide

  27. 4DBMBίϯύΠϥʹΑΔ
    ࠷దԽ
    w ಛघԽ
    w ܕύϥϝʔλʹ@specializedΞϊςʔγϣϯΛ͚ͭΔ͜ͱͰࢦఆ
    w ܕύϥϝʔλ͕ϓϦϛςΟϒܕͷ৔߹ʹରͯ͠ɺઐ༻ͷϝιουΛ
    ੜ੒͢Δ͜ͱͰCPYJOHΛෆཁʹ
    w ૊Έ߹Θͤͷ਺͚ͩϝιουΫϥε͕૿͑Δͱ͍͏σϝϦοτ͋Γ
    w ૊Έ߹Θͤ਺ΛݮΒ͢NJOJCPYJOHͱ͍͏ख๏΋͋Δ ͨͩ͠4DBMB
    ຊՈʹ͸ೖͬͯͳ͠

    trait Function1[
    @specialized(scala.Int, scala.Long, scala.Float, scala.Double) -T1,
    @specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double) +R
    ] extends AnyRef { self =>
    ྫ: scala.Function1ͷఆٛ

    View full-size slide

  28. 4DBMBίϯύΠϥʹΑΔ
    ࠷దԽ
    w &MJNJOBUFOPOFTDBQJOHCPYFT UVQMFT
    BOESFGT
    w ίϯύΠϧ࣌ʹɺϝιου಺Ͱ׬͍݁ͯ͠Δ
    CPYJOHUVQMJOHΛআڈ͢Δ
    w ͰೖΔΒ͍͠Ͱ͢
    w ϝιουΛ·͍ͨͩ࠷దԽͰ͸ͳ͍ͷͰɺޮՌ͸͔
    ͳΓݶఆతͰ͸ͱ͍͏ؾ͕͠·͢

    View full-size slide

  29. +7.ʹΑΔ࠷దԽ
    w ΤεέʔϓղੳʹΑΔΠϯελϯεੜ੒আڈ
    w Ұൠతʹ͸4DBMBSSFQMBDFNFOUͳͲͱ͍͏
    Β͍͠
    w ϝιου֎ʹ࿐ग़͍ͯ͠ͳ͍ΦϒδΣΫτΛΠϯ
    ϥΠϯԽ
    w ߴ଎ͳϝϞϦ֬อͱ($ॲཧ
    w OFX΍($ͷίετΛۃݶ·ͰݮΒͤ͹Ͳ͏ͱ͍
    ͏͜ͱ͸ͳ͍

    View full-size slide

  30. Ծ૝ؔ਺ݺͼग़͠
    w SFDFJWFSͷΫϥεΛݩʹಈతʹݺͼઌΛม͑Δ
    w ༧ଌࠔ೉ͳؒ઀෼ذ͸ޮ཰͕ѱ͍
    w Ծ૝Ͱͳͯ͘΋ɺؔ਺ݺͼग़͠͸ίετ͕͔͔Δ
    w ϓϩάϥϜͷෳࡶԽ͸࠷దԽΛ્֐͢Δ
    class A {
    def foo: Int = 10
    }
    class B extends A {
    def foo = 99
    }
    class X {
    def bar(a: A) =
    a.foo // 10? 99?
    }

    View full-size slide

  31. 4DBMBίϯύΠϥʹΑΔ
    ࠷దԽ
    w !JOMJOF
    w Ξϊςʔγϣϯ͕ࢦఆ͞Εͨϝιουͷݺͼग़͠
    ΛίϯύΠϧ࣌ʹΠϯϥΠϯԽ
    w ຤ඌ࠶ؼ࠷దԽ!UBJMSFD
    w ຤ඌ࠶ؼݺͼग़͠Λϧʔϓʹల։

    View full-size slide

  32. +7.ʹΑΔ࠷దԽ
    w *OMJOJOH
    w Α͘ݺͼग़͞ΕΔখ͍͞ϝιουΛ࣮ߦ࣌ʹΠϯ
    ϥΠϯల։͢Δ
    w ݺͼग़͞ΕΔϝιουͷީิ͕ݶΒΕ͍ͯΔ৔߹ɺ
    Ծ૝ؔ਺ݺͼग़͠ΛܕνΣοΫ௚઀ݺͼग़͠ʹม
    ׵
    w +*5ίϯύΠϥͷৄࡉʹؔ͢Δࢿྉ͸๡͍͠ͷͰɺ
    ΘΓͱṖʹแ·Ε͍ͯ·͢ 0QFO+%,ͷίʔυΛ
    ͕Μ͹ͬͯಡΊ͹͍͍ΜͰ͕͢ʜʜ

    View full-size slide

  33. $IBQUFSطଘͷ
    ࠷దԽ͸े෼͔

    View full-size slide

  34. "SSPXͷओ໾͸
    ؔ਺߹੒

    View full-size slide

  35. ؔ਺߹੒ͷ
    ύϑΥʔϚϯεΛ
    ଌఆͯ͠ΈΔ

    View full-size slide

  36. ؔ਺߹੒ͷ
    ύϑΥʔϚϯε
    w YTMPXFS
    standardF ௨ৗͷؔ਺߹੒ 4515.900 ± 154.250
    baseline ߹੒ͤͣ௚઀ݺͿ 21772.108 ± 154.944
    val f1: Int => Int = { x => x + 1 }
    val f2: Int => Double = { x => x + 10.0 }
    val f3: Double => Int = { x => (x * 100).toInt }
    val f4: Int => Double = { x => x + 1.5 }
    val f5: Double => Double = { x => x * 0.01 }
    val f6: Double => Double = { x => x - 200.0 }
    val f7: Double => Int = { x => x.toInt }
    val f8: Int => Int = { x => x + 10 }
    !
    val baseline = {
    def F(x: Int) = f8(f7(f6(f5(f4(f3(f2(f1(x))))))))
    x: Int => F(F(F(F(x))))
    }
    !
    val standardF = {
    def F = f1 andThen f2 andThen f3 andThen f4 andThen f5 andThen f6 andThen f7 andThen f8
    F andThen F andThen F andThen F
    }

    View full-size slide

  37. 4DBMBʹ͓͚Δؔ਺߹੒
    class Comopse[A, B, C](
    f: Function1[A, B],
    g: Function1[B, C]
    ) extends Function1[A, B] {
    def apply(x: A) = g(f(a))
    }
    Compose
    Function1 Compose
    Function1
    Compose
    Function1 Compose
    Function1 Function1

    View full-size slide

  38. ؔ਺߹੒͸
    ಛघԽ͞Ε͍ͯͳ͍
    • unspecialized(´ŋ_ŋ`)
    w ૊Έ߹ΘͤരൃΛݮΒͨ͢Ίͷ൑அͩͱࢥΘΕ·͢
    @annotation.unspecialized
    def andThen[A](g: R => A): T1 => A =
    { x => g(apply(x)) }

    View full-size slide

  39. Fun1[Int,(Int, Int)]
    ͸ಛघԽ͞Εͳ͍
    w 'VODUJPOͷಛघԽ͸ɺҰ෦ͷ૊Έ߹Θͤʹݶఆ
    w Ҿ਺ɾฦΓ஋ͷҰ෦͕ࢀরܕͷέʔε͸ɺಛघԽͷର৅ʹ
    ͳΒͳ͍
    w Ϋϥεɾϝιου਺ͷ૿ՃͱύϑΥʔϚϯε޲্Λఱṝʹ
    ͔͚ͨ݁ՌͩͱࢥΘΕΔ

    View full-size slide

  40. +*5ίϯύΠϥʹΑΔ
    JOMJOJOH΋ແཧ
    w 'VODUJPOͷαϒΫϥε͸େྔʹଘࡏ
    w ͭ·Γɺݺͼग़͞ΕΔՄೳੑͷ͋ΔԾ૝ؔ਺ͷީิ
    ͕େྔʹ͋Δ
    w ࠷దԽ્͕֐͞Ε͍ͯΔ͓ͦΕ

    View full-size slide

  41. +*5ίϯύΠϥ͸
    #PYJOHΛಛʹέΞͯ͠ͳ͍
    w ˞ࢿྉ͕๡͍͠ͷͰਪଌͰ͢
    w JOMJOJOH͕੒ޭ͢Ε͹ ͯ͠ͳ͍
    ɺΤεέʔϓղੳ
    ͰআڈͰ͖Δ͕ʜʜ

    View full-size slide

  42. ίϯύΠϧ࣌ͷ
    ࠷దԽ͸
    ݶք͕͋Δ
    w ϥΠϒϥϦ͸ಈతʹϦϯΫ͞ΕΔͷͰɺΫϥεΛ௒
    ͑ͨ࠷దԽ͸ඇৗʹ೉͍͠
    w ಛघԽ͸ɺࣄલʹ͢΂ͯͷϓϦϛςΟϒܕͷ૊Έ߹
    ΘͤΛ४උ͢Δ͜ͱ͸ࠔ೉ˠޮՌ͕ݶఆ͞ΕΔ
    w NJOJCPYJOHΈ͍ͨͳςΫ͸͋Δ͚Ͳඪ४ϥΠ
    ϒϥϦʹಋೖ͞Εͯͳ͍ΜͰʜʜ

    View full-size slide

  43. +*5ίϯύΠϧʹ͸
    ݶք͕͋Δ
    w ಁաతʹಈ࡞͢Δඞཁ͕͋Δ
    w ॲཧ࣌ؒͷ੍໿
    w ͍͔ͳΔ৔߹΋ڍಈมߋͯ͠͸ͳΒͳ͍
    w ͋ΒΏΔϓϩάϥϜʹରͯ͠ɺͦΕͳΓʹಈ͘ඞ
    ཁ͕͋Δ

    View full-size slide

  44. $IBQUFS
    !
    खܰͳ࣮૷Ͱ
    ؔ਺߹੒ͷߴ଎Խ

    View full-size slide

  45. 4DBMBίϯύΠϥʹ΋
    +7.ʹ΋ແཧͳΒɺ
    ࣗલͰ࠷దԽ͢Δ͔͠ͳ͍
    w ॲཧ࣌ؒͷ੍໿ͳ͠
    w ڍಈΛม͑ͯ΋͍͍
    w ݶఆ͞Εͨ໨తͷͨΊͷ࠷దԽ͕Ͱ͖Δ

    View full-size slide

  46. ࣮ߦϑΣʔζͷ෼ղ
    w ໨తͷΞϓϦέʔγϣϯ͸ɺΦϒδΣΫτάϥϑͷ
    ߏஙˠ࣮ߦͱ͍͏ߏ੒
    def main() = {
    // ΦϒδΣΫτάϥϑͷߏங
    val arrow: Long => Double =
    buildArrow()
    // ࣮ߦ
    while(true) {
    run(arrow)
    }
    }

    View full-size slide

  47. ΞϓϦέʔγϣϯಛੑʹ
    جͮ͘࠷దԽ
    w ΦϒδΣΫτάϥϑͷߏங͸࠷ॳ͚ͩ
    w ͜ͷ෦෼ͷύϑΥʔϚϯε͸ॏཁͰ͸ͳ͍
    w ߏங͞Εͨάϥϑ͸ଟ਺࣮ߦ͞ΕΔ
    w ͖ΘΊͯߴ଎ʹ࣮ߦ͍ͨ͠

    View full-size slide

  48. ࠷దԽϑΣʔζͷಋೖ
    def main() = {
    // ΦϒδΣΫτάϥϑͷߏங
    val arrow: Long => Double =
    buildArrow()
    // ࠷దԽ
    val optimized = optimize(arrow)
    // ࣮ߦ
    while(true) {
    run(optimized)
    }
    }

    View full-size slide

  49. खܰͳ࣮૷Ͱ
    ߴ଎Խͯ͠ΈΔ
    w ؔ਺߹੒ΛΫϥεʹ·ͱΊɺಛघԽϝιουΛ࢖
    ͏
    w Ծ૝ϝιουݺͼग़͠ͱCPYJOH͕໰୊
    w $PNQPTF/Έ͍ͨͳΫϥε࡞Ε͹ղܾ͢Δ
    w ࣄલʹશύλʔϯੜ੒͸ݱ࣮తͰ͸ͳ͍ͷͰɺ࣮ߦ
    ࣌ʹ΍Δ

    View full-size slide

  50. Ϋϥεੜ੒ʹΑΔ࣮૷
    w +BWBTTJTUϥΠϒϥϦͰ͜͏͍͏ΫϥεΛಈతʹ
    ࡞Δ
    clas Compose5 extends Function1 {
    val f1: Function1
    val f2: Function1
    // ...
    def apply(a: Any) = apply$ID(a)
    def apply$ID(a: Int): Double = {
    f5$ID(f4$II(f3$DI(f2$ID(f1$II(a))))
    }
    // ...
    }

    View full-size slide

  51. Ϋϥεੜ੒ʹΑΔ࣮૷
    w ίʔϧελοΫ͕ઙ͘ͳΔ
    w ϝιουݺͼग़͠ίετͷ௿ݮ
    w +*5ίϯύΠϥ΁ͷ༏͠͞
    w CPYJOHͷআڈ
    w ͕ظ଴Ͱ͖Δ

    View full-size slide

  52. MethodHandleʹΑΔ࣮૷
    w MethodHandle+7.ʹ͓͚Δؔ਺ϙΠϯλ
    w +7.͕ಛผѻ͍ͯ͘͠ΕΔͷͰ࠷దԽͷΦϙνϡ
    χςΟ͕͓͓͖͍
    w +7.࢓༷Ͱ΋ϝιουݺͼग़࣌͠ͷಛผѻ͍͕໌
    ݴ͞ΕͯΔ
    w .)ͷ߹੒΋αϙʔτ͍ͯ͠Δ

    View full-size slide

  53. MethodHandle API
    w MethodHandles.identity(klass)߃౳ؔ਺
    w MethodHandles.lookup().findVirtual(klass,
    name, type).bind(obj):ಛఆͷΠϯελϯεͷ
    Ծ૝ؔ਺Λද͢.)ΛಘΔ
    w MethodHandles.filterReturnValue(mh1, mh2)
    .)ͷฦΓ஋ʹผͷ.)Λద༻
    w ͜ΕΒΛ࢖͑͹ؔ਺߹੒͕දݱՄೳ

    View full-size slide

  54. ϕϯνϚʔΫ݁Ռ
    w ͪΐͬͱ଎͘ͳΓ·ͨ͠Ͷ
    w .FUIPE)BOEMF࢖͑͹Ϋϥεੜ੒ͳ͠ͰΦʔό
    ϔου࡟ݮͰ͖ΔͷͰ͓ಘ
    w ͔͠͠CBTFMJOF·Ͱ͸ԕ͍
    standard ௨ৗͷؔ਺߹੒ 4515.900 ± 154.250
    fast ߹੒Ϋϥεͷੜ੒ 5499.803 ± 183.904
    fastMH MethodHandleʹΑΔ߹੒ 5476.340 ± 45.937
    baseline ߹੒ͤͣ௚઀ݺͿ 21772.108 ± 154.944
    ୯Ґ: k ops/sec

    View full-size slide

  55. ίʔυެ։ͯ͠·͢
    w IUUQTHJUIVCDPNUPEFTLJOH
    GBTU@GVODUJPO@DPNQPTFSTDBMB

    View full-size slide

  56. $IBQUFS
    !
    ൚༻ੑͷ͋Δ
    ࣮ߦ࣌
    όΠτίʔυ࠷దԽ

    View full-size slide

  57. ߟ͑ํ
    w ϑΟʔϧυΛ༥߹ͤͯ͞Ծ૝ؔ਺ݺͼग़͠Λ࡟ݮ
    w ϑΟʔϧυ಺ͰϝιουͷΠϯϥΠϯԽ

    View full-size slide

  58. ϑΟʔϧυͷ༥߹
    w Ծ૝ؔ਺ݺͼग़͠Λ࣮ؔ਺ݺͼग़͠ʹม׵Ͱ͖Δ
    w +*5ίϯύΠϧͰͷ࠷దԽ΋͖͖΍͘͢ͳΔ͔΋
    class A(b: B) {
    def foo = b.bar + 1
    }
    class B(c: C) {
    def bar = 99 + c.baz
    }
    class C {
    def baz = 111
    }
    class A_opt(b: B) extends A{
    def foo = b_bar + 1
    def b_bar = 99 + b_c_baz
    def b_c_baz = 111
    }

    View full-size slide

  59. ϝιουͷΠϯϥΠϯԽ
    w ϑΟʔϧυ༥߹ޙɺಉҰΠϯελϯε಺Ͱͷϝιο
    υΠϯϥΠϯԽΛߦ͏
    class A_opt(b: B) extends A{
    def foo = b_bar + 1
    def b_bar = 99 + b_c_baz
    def b_c_baz = 111
    }
    class A_opt2(b: B) extends A{
    def foo =
    99 + 111 + 1
    }

    View full-size slide

  60. ϕϯν݁Ռ
    w ر๬͕ݟ͖͑ͯ·ͨ͠Ͷ
    w ؔ਺ݺͼग़͠ίετͷపఈͨ͠࡟ݮͱɺ+*5ίϯύΠϧʹΑΔ
    ࠷దԽ͕ޮ͖΍͍͢ܗࣜʹͳͬͨ͜ͱ͕଎౓ʹͭͳ͕ͬͨͱݟ
    ͍ͯ·͢
    w CBTFMJOFͱͷࠩ͸ɺCPYJOH͕ফͤͯͳ͍ͷ͕ؔ܎ͯͦ͠͏
    standard ௨ৗͷؔ਺߹੒ 4640.914 ± 77.983
    fused Field fusionద༻ 7187.380 ± 321.257
    fuseInlined Field Fusion + Method Inlining 12924.076 ± 207.785
    baseline ߹੒ͤͣ௚઀ݺͿ 21841.596 ± 223.906
    ୯Ґ: k ops/sec

    View full-size slide

  61. ൚༻ੑ͕͋Δ
    w ؔ਺߹੒ʹݶఆ͞Εͳ͍ɺ൚༻తͳΦϒδΣΫτά
    ϥϑͷ࠷దԽ͕ՄೳͱͳΔ
    w ͔͍͍ͬ͜͠ɺ࣮༻ੑ͕͋Δ<ཁग़య>

    View full-size slide

  62. ࣮૷ͷৄࡉ
    w ΫϥεϑΝΠϧૢ࡞ʹ͸+BWBTTJTUΛ࢖༻
    w όΠτίʔυղੳͳͲ͸αϙʔτ͕ͳ͍ͷͰࣗલ
    Ͱ΍ͬͯ·͢

    View full-size slide

  63. ࣮૷ͷৄࡉ
    'JFMEGVTJPO
    w ࢖༻͞Ε͍ͯΔϝιουͷಛఆ
    w ͦΕΒͷϝιου͕ґଘ͍ͯ͠Δϝιουͷಛఆ
    w ͦΕΒͷϝιου͕࢖༻͍ͯ͠ΔϑΟʔϧυΛ߹੒
    w ϝιουࢀরͷॻ͖׵͑

    View full-size slide

  64. όΠτίʔυղੳ
    w UIJTʹର͢Δૢ࡞Λॻ͖׵͍͑ͨ
    w ಛఆͷϑΟʔϧυʹର͢Δؔ਺ݺͼग़͠Λॻ͖׵͑
    ͍ͨ
    w ͳͲͷधཁ͕͋ΓɺόΠτίʔυΛղੳͯͦ͠ΕΒ
    ͷ৘ใΛಘΔඞཁ͕͋Γ·͢

    View full-size slide

  65. #ZUFDPEF
    w +7.͸ελοΫϚγϯ
    w ϝιουϩʔΧϧͷ஋͸ελοΫͱϩʔΧϧม਺ʹ
    อଘ͞ΕΔ
    w ஋ʹ͸ܕ͕͋Δ
    w Ϋϥε࢖༻࣌ʹܕ͕߹͍ͬͯΔ͔+7.͕ݕূ

    View full-size slide

  66. σʔλϑϩʔղੳ
    w +7.4Ͱݴٴ͞ΕͯΔ΍ͭͱ͍͍͓ͩͨͳ͡Ͱ͢

    View full-size slide

  67. Ϋϥεͷมܗ͸೉͍͠
    w ϝϯόʹ͸ΞΫηεݖ͕͋Δ
    w QSJWBUFϑΟʔϧυΛࢀর͍ͯ͠ΔQVCMJDϝιο
    υΛॻ͖׵͑Δʹ͸ɺͦͷϑΟʔϧυ΋Ұॹʹ࣋ͬ
    ͯ͘Δඞཁ͕͋Δ
    w ύϑΥʔϚϯεతͳཧ༝͔ΒɺϦϑϨΫγϣϯ͸࢖
    ͍·ͤΜ

    View full-size slide

  68. Ϋϥεੜ੒
    w ϑΟʔϧυʹద੾ͳ஋Ληοτ͢Δඞཁ͕͋Δ
    w ਌ΫϥεͷpOBMϑΟʔϧυʹ΋
    w ਌ΫϥεͷίϯετϥΫλʹ͸ద੾ͳ஋Λ౉͞Ͷ͹
    ͳΒͳ͍
    w ਌ͷίϯετϥΫλΛղੳͯ͠Ҿ਺ͱϑΟʔϧυͷ
    ؔ܎ΛϚοϐϯά͠ɺͦΕΛݩʹίϯετϥΫλ࣮
    ૷ͱҾ਺ΛٻΊΔ

    View full-size slide

  69. Ϋϥεੜ੒
    ίϯετϥΫλղੳ
    w $ͷαϒΫϥεΛఆ͍ٛͨ͠
    w "Yͷ஋͸"ίϯετϥΫλͷୈҰҾ਺͕࢖ΘΕΔ
    w #Zͷ஋͸#ίϯετϥΫλͷୈҰҐҾ਺͕࢖ΘΕΔ
    w #ίϯετϥΫλ͸"
    ΛݺͿ
    w $ίϯετϥΫλͷҾ਺͸Ͱ͋Δ΂͖
    w ͱ͍͏͜ͱΛɺϑΟʔϧυͷ஋ͱ֤Ϋϥεఆ͔ٛΒٻΊΔ
    class A(val x: Int)
    class B(val y: Int) extends A(1)
    class C(val x: Int) extends B(x)
    !
    optimize(new C(1))

    View full-size slide

  70. ࣮ࡍͷมܗ
    w ΦϒδΣΫτͷωετ͕ਂ͗ͯ͢ϑΟʔϧυ໊͕͍͢͜͝ͱʹ
    w ΫϥεϑΝΠϧͷϝϯό਺੍ݶ΍Ҿ਺ɺόΠτίʔυ௕ͷ੍ݶ
    ͳͲ΋ߟྀ͠ͳ͍ͱ·ͣͦ͏ͳ༧ײ͕͠·͢

    View full-size slide

  71. ίʔυެ։ͯ͠·͢
    w IUUQTHJUIVCDPNUPEFTLJOH6OWFJM

    View full-size slide

  72. $IBQUFS·ͱΊ

    View full-size slide

  73. ·ͱΊ
    w ࣮ߦ࣌ʹόΠτίʔυΛ࠷దԽͯ͠ΦʔόϔουΛ
    ݮΒͨ͢Ίͷख๏Λఏࣔ͠·ͨ͠
    w ந৅ԽΛอͪͳ͕Β࣮ߦ࣌ͷ଎౓Λ޲্ͤ͞ΒΕΔ
    ر๬͕ݟ͖͑ͯͨ

    View full-size slide

  74. ͲΜͳͱ͖ʹ༗ޮͳͷ
    ͔
    w খ͞ͳΦϒδΣΫτ͕ଟ਺߹੒͞Ε͍ͯΔ
    w ΦϒδΣΫτͷੜ੒ճ਺࣮ߦճ਺
    w ຊ౰ʹύϑΥʔϚϯε΍ϨΠςϯγ͕ॏཁ
    w ந৅ԽΛࣺͯͨ͘ͳ͍
    w ৴߸ॲཧҎ֎ͩͱ
    w ݴޠॲཧܥ
    w Ҩ఻తϓϩάϥϛϯά
    w +BWBͷ1BUUFSOΫϥεʹ΋ద༻Ͱ͖Δ͔΋

    View full-size slide

  75. ࠓޙͷల๬
    w ·ͩαϙʔτͯ͠ͳ͍ཁૉ͕ଟ͍
    w OFXͱ͔ྫ֎ϋϯυϥͱ͔
    w ΠϯλϑΣʔεͷσϑΥϧτ࣮૷΍*O%Z
    w 4DBMBͰ࢖ͬͯͳ͍͍͍͔͠ͱࢥͬͨΒɺ࠾༻
    ͷಈ͖͕
    w ҆શͳॻ͖׵͑ͷอো
    w ͜ͷॻ͖׵͑͸Ͳ͏͍ͬͨ৚݅ͷ΋ͱͰ҆શͳͷ
    ͔ ͱ͍͏ͷΛ։ൃऀͷצʹཔ͍ͬͯΔ
    w ܗࣜతख๏ɺಋೖ͍ͨ͠Ͱ͢Ͷʜʜ

    View full-size slide

  76. ؔ࿈ࢿྉ
    w 4PPU
    w όΠτίʔυղੳ࠷దԽϥΠϒϥϦͷ࿝ฮ
    w ͪ͜Β͸੩తͳม׵Λલఏͱ͍ͯ͠ΔΑ͏Ͱ͢
    w 4USFBN+*5
    w $PNNFOTBM$PNQJMFS֓೦
    w .FUIPE)BOEMFͷݩωλ
    w ੴ࡚Ұ໌ࢯͷ֤छࢿྉ
    w +7.͕࠾༻͍ͯ͠Δ࠷దԽख๏ʹ͍ͭͯͷوॏͳࢿྉ
    w ೥୅લ൒ʹॻ͔Εͨ΋ͷͰ͕͢ɺ+*5ίϯύΠϥͷॲཧʹͭ
    ͍ͯॻ͔Εͨࢿྉ͸ຊ౰ʹগͳ͍ͷͰوॏ
    w (JPSHJE[F (FPSHF.PEVMBS4ZOUIFTJ[FS1SPHSBNNJOHJO)BTLFMM%JTT.4D%JTTFSUBUJPO
    %FQBSUNFOUPG$PNQVUFS4DJFODFBOE&OHJOFFSJOH %JWJTJPOPG$PNQVUJOH4DJFODF $IBMNFST
    6OJWFSTJUZPG5FDIOPMPHZBOE5IF6OJWFSTJUZPG(PUIFOCVSH (PUIFOCVSH 4XFEFO
    w )BLFMM:BNQBͰϞδϡϥʔγϯη࡞Δ࿩

    View full-size slide