uPython 3.13vŒljꂽJITRpCƂ́HFPythonŐVLb`Abv - IT

uPython 3.13vŒljꂽJITRpCƂ́HFPythonŐVLb`Abv

Python͈ȑO炻̎sx_ƂĂB傫P”\JITRpCPython 3.13ł͎IɃT|[gꂽBꂪǂȂ̂Ă݂悤B

» 2024N1122 0500 J
[CDeep InsiderҏW]
uPythonŐVLb`AbvṽCfbNX

Aږڎ

@OPython 3.13̐V@\VREPLƁAt[Xbh[hɂ‚ČB͎Iɒljꂽ@\łuJITRpCvɂ‚ČĂ݂悤B

IɃT|[gꂽJITRpC

@Python 3.13iCPython 3.13jłJITRpC̃T|[gIɒljꂽBApython.org_E[h”\ȏnɂJITRpC͊܂܂ĂȂB̂߁AJITRpCۂɎĂ݂ɂ͎CPython 3.13rhKvB

@JITRpCLɂCPythonrh@CPythoñ|WgŐĂBŁȀɕM҂ۂɈȉ̊‹CPython 3.13rhāAJITRpCLȏԂłƂR[hsāAPythonvO̎sǂ̂炢ɂȂ邩𒲂ׂĂ݂B

  • Mac mini 2020îMac mini 2018j
  • CPUFIntel Core i3i4RA4Xbhj
  • F16GB
  • OSFmacOS Sequoia 15.1

@NłLLVM 19CXg[悤Ɏw邪AM҂ƂłLLVM 18CXg[KvBurhɎsvƂCɂĂ݂ĂقBȊOconfigureR}hiXNvgjɁu--enable-experimental-jitvIvVw肷Ƃ܂߂āAhLg̎wɏ]ƂŃrhiASSL֘A̋@\ɂ‚Ă̓rhłĂȂƎvBAł͖BȂ񂩉G[̂悤ȋCjB

@rhCPythońumake installvR}hɂ/usr/local/bin/python3.13iт̃V{bNNł/usr/local/bin/python3jƂăCXg[邪AM҂̊‹ɂ͊python.org_E[hPython 3.13CXg[ĂāAupython3vR}h邢́upython3.13vR}hsƁA炪NĂ܂߁Ał͎ŃrhCPythoniւ̃V{bNNj̃t@Cu/usr/local/bin/python3jvƕύXiujv́uJITvӖjB

@ۂɎĂ݂R[h͈ȉB|Ȃ܂tB{ib`ċAŌvZ֐`āAfib(40)Ăяo̎sԂ̌v10JԂāA̕ώԂ߂ĂB

import time

def fib(n):
    if n == 0 or n == 1:
        return 1
    return fib(n - 1) + fib(n - 2)


if __name__ == '__main__':
    diffs = []
    for n in range(10):
        print(f'#{n} ', end='')
        st = time.time()
        fib(40)
        ed = time.time()
        diff = ed - st
        print(f'time: {diff}')
        diffs.append(diff)

    print(f'\navg: {sum(diffs) / len(diffs)}')

ʂJITRpCɂ荂͎̂

@M҂̎茳ɂ͊‚̃o[WPythonCXg[Ă̂ŁAgďLvOisample.pyjsĂ݂B

Python 3.10JITRpCLɂPython 3.13PythonR[hsĂƂ Python 3.10JITRpCLɂPython 3.13PythonR[hsĂƂ

@Python 3.10JITRpCLɂPython 3.13ł͂Ȃ̑x邱ƂBȂAPython 3.10ȍ~̊eo[WŎsԂvʂ͈ȉ̂悤ɂȂiM҂̊‹ł̌vlBvOǎ҂ʂ̊‹Ŏsꍇɂ́A̒lقȂ̂ɂȂ邾낤BAS̓IȌX͓lɂȂƎvjB

o[W sԁi10̕ϒlj
Python 3.10 37.9b
Python 3.11 18.8b
Python 3.12 21.4b
Python 3.13 21.4b
Python 3.13iJITRpCLj 18.1b
Pythoño[WƂ̎s

@Python 3.10ł40b߂Ă̂APython 3.11ł͑傫ĂBPython 3.12Python 3.13iJITRpCLłȂ́jł́Ax኱ቺĂ邪A̗R͕M҂ɂ͐łȂBAJITRpCLɂPython 3.13łPython 3.11Ɠ炢ɍɂȂĂB

@Python 3.13JITRpCLƂϓ_Ō΁A3bĂB傴ςɍl΁A15̑xƂ邾낤B̂悤JITRpCɂsxシʂƂẮA[vœ̌^̃f[^xꍇ⓯֐xĂяoꍇȂǂB

@Python 3.11ȍ~łȂقǂ̍ȂƂƁAFaster CPythonƂvWFNgɂ̂B

JITRpCo܂ł̓̂

@Faster CPythonvWFNgł͂ƂƁAPython 3.10ȍ~4o[W1.5{‚̍ڎwĂBPython 3.10ł́uadaptive, specializing interpreterv̓v悳ĂAۂɂPython 3.11ŁuSpecializing Adaptive InterpretervƂēĂiPEP 659jB

@Specializing Adaptive Interpreter邩̑OɁAPythonR[h̎sɂ‚ĊȒPɂ܂Ƃ߂ƁAPythonR[h͂̂܂܃C^[v^ŝł͂ȂȂOɃoCgR[hɕϊAꂪVMŎsioCgR[ht@CɃLbV̂.pyct@CłjBǂȃoCgR[h߂邩̓oCgR[htAZu邽߂disW[̃hLgɂuPythonoCgR[hvŎQƂłB

@̂悤ȃoCgR[h́ioCgR[hɌȂjApɂɎs镔ƂȂɎs镔AقƂǎsȂɕBFaster CPythonvWFNgł͂ꂼzbgR[hihot codejAEH[R[hiwarm codejAR[hR[hicold codejƌĂłB܂A܂Ƃ܂R[h͈͂\[WiregionjƂTOB

@āAoCgR[h̎siKTier 0Tier 34‚̑wɕĂifobOvt@COړIƂTier -1邪ł͏ȗjBȒPɂ܂Ƃ߂ƁATier 0̓R[hR[hswATier 1̓EH[R[hswATier 2Tier 3̓zbgR[hswƂȂBTier 0ŃR[hR[hsꂽAxTier 0ł̃R[hsƁA̓EH[R[hƂȂTier 1Ɉړi̓W[̃gbvxɂ֐`NX`ȂǁAxsȂƂmȃR[hƂȊÕR[h𕪂̂ɖ𗧂jBTier 2Tier 3̈Ⴂ́A⃊\[X̏Ɋ֌WBzbgR[h͍ɎsׂłAJITRpC₻ɔœK̑ΏۂƂȂ邪A⃊\[XߏɏȂƂlȂTier 2ŁAłȂTier 3ŎsiAPython 3.13œJITRpCTier 2ΏۂƂjB

Specializing Adaptive InterpreteriꉻKIC^[v^j

@Python 3.11Specializing Adaptive InterpreteriꉻKIC^[v^j͂̂Tier 1œ삷̂ƎviƂ̂́AuWhat's New In Python 3.13vɂ́uWe start with specialized Tier 1 bytecodevƂLqÁuspecializedvSpecializing Adaptive Interpreterɂ鏈sꂽƂӖĂ邩炾jB

@Specializing Adaptive Interpreter邩ƂƁAuIɕωIuWFNg^ɑΉĂ܂܂ȏoCgR[hǍ^ɓoCgR[hւƓꉻiujvƂƍlBł2Zqu+vɑΉoCgR[hǂω邩Ă݂悤BȉɊȒPȗB

def foo(a, b):
    return a + b

2Zqu+vgfoo֐̒`

@disW[dis֐ŋtAZuƂ̃oCgR[hmFłishow_cachesp[^[̓LbVAadaptivep[^[Specializing Adaptive InterpreterɂēꉻꂽoCgR[h\邩ǂw肷jBłJITRpCLPython 3.13gpB

import dis

dis.dis(foo, show_caches=True, adaptive=True)

foo֐̃oCgR[hmF

@sʂȉɎB

foo֐̃oCgR[h foo֐̃oCgR[h

@ł2Zqu+vɑΉoCgR[huBINARY_OPvł邱ƂBɂ̊֐xĂяoĂdis.dis֐ēxĂяo݂B

foo(0, 1)
foo(0, 1)
dis.dis(foo, show_caches=True, adaptive=True)

oCgR[hω邩ǂmF

@sʂȉɎB

oCgR[hω oCgR[hω

@̂悤ɃoCgR[huBINARY_OP_ADD_INTvɕωBBINARY_OP͂܂܂ȃIuWFNǧ^ɑΉi|tBbNȁjoCgR[hABINARY_OP_ADD_INTint^̃IuWFNg̉Zɓ2ZqłB퉉ZqiIyhjɐ^ł΁A^`FbNƌ^ɉ̃fBXpb`ȂǂsvłA^ɓoCgR[hs邱Ƃł̎sx܂Ɗ҂łî悤ȐU镑̌ʂPython 3.10Python 3.11ł̖`̃tB{ib`vZR[h̑xɂ‚ȂĂƐłjBȂA^ȊÕIuWFNgoƂɂ͈ȑÕ|tBbNȃR[hւƎs̓tH[obNB

@܂AĂяoO̊֐̓R[hR[hłAxĂяoƂł̊֐̓EH[R[hɂȂATier 1ɈړĂ_oĂB

@悤Python͓I^tł邪A鏈s蕔ɒڂƂAIuWFNg₻̌^ω邱Ƃ͑Ȃiu^萫vutype stabilityvƂjB̂ƂpāA鏈ɑΉoCgR[ĥƂɈĂIuWFNǧ^ɍ킹ēꉻ悤Ƃ̂Specializing Adaptive Interpreter̖ƂB

JITRpC

@ȉPython 3.13́uWhat's New In Python 3.13vɏĂJITRpC̊Tv̈ꕔM҂Kɖ󂵂̂iPython 3.13ɂJITRpC̐݌vj̊Tvɂ‚ẮuPEP 744vڂjB

  • ꉻꂽTier 1̃oCgR[hƂ
  • Tier 1̃oCgR[hzbgR[hƔfƁAsAȒԕ\iintermediate representationAIRjɕϊBTier 2 IRƂumicro-opsviuopsjƌĂԂƂ
  • Tier 2 IRTier 1ƓX^bNx[XVMgp邪A̖߃tH[}bg̓}VR[hւ̕ϊɂK̂ɂȂĂ
  • Tier 2 IRɂ͊‚̍œK@A}VR[hւ̕ϊOɂ炪Kp
  • JITVsĂꍇAœKꂽTier 2 IR̎sɃ}VR[hɕϊAs
  • }VR[hւ̕ϊɂ́ARs[pb`ƌĂ΂@g

@ꉻꂽTier 1̃oCgR[hƂ́AŌ悤Ɍ^萫pēꉻꂽoCgR[ĥƂBꉻꂽTier 1̃oCgR[h܂ރR[hpɂɎsiႦ΁A`̃tB{ib`vZ֐ċAsʼnxĂяoꂽA̒ŐZxsꂽ肷邱ƂŁjAzbgR[hłƔfƁAȀsoCgR[h͂菬ȏPʂłumicro-opsv܂񂾃oCgR[hɕϊ*1B

@Specializing Adaptive Interpreterɂꉻ͒P̃oCgR[h^ɓoCgR[hɓꉻ̂A̒iKōŝ͂傫ȈȀΏۂƂiႦ΁Afor[vƂ̓ōs鏈ȂǁjBāAmicro-ops܂ނ悤ɂȂoCgR[h́A̎sOɍœKꂽɃ}VR[hɕϊĎۂɎsB

@oCgR[h̃}VR[hւ̕ϊł́uRs[pb`vƌĂ΂@gBRs[pb`Ƃ̓oCgR[hƂɗpӂĂ^̃oCiR[hiev[gƂXeVƌĂԁĵǂɃRs[āAs}VR[hƂĂ܂Ƃ̂BAev[giXeVjɂ́AoCgR[h̃Iyhɑ镔Ɂuv󂢂ĂBāǍ̂Ƃǂɉli2̐ZZł2‚̐ljŖ߂邱ƂŁipb`jAۂɎs”\ȃR[hƂB̂ǂɃev[gRs[邩͕Ȃ̂ŁAev[g̃R[h̓P[^uiAhXɈˑɍĔzu”\jɂȂĂiWv͐΃AhXł͂Ȃ΃AhXgpȂǁjB

@Ɛ}ɂ܂Ƃ߂̂ȉB

Python 3.13ŎIɃT|[gJITRpC̋@\iTier 3ɂ‚Ă͏ȗj Python 3.13ŎIɃT|[gJITRpC̋@\iTier 3ɂ‚Ă͏ȗj

*1@Python 3.12ȍ~ł́ACꃉCNDSLiDomain Specific LanguagejgċLqꂽoCgR[h̃CXgNV`oCgR[hC^[v^悤ɂȂĂB̉b̈‚ƂāAoCgR[hmicro-opsɕϊ邽߂̃e[u̎”\ɂȂĂB


@PythonɂJIT̃T|[g͂܂IȂ̂ł͂邪A{L̖`Ō悤ɂx̍]߂̂ɂȂĂB̈ŁAPythonR[ĥǂzbgȂ̂𔻒fɂ̓R[h̃g[XKvAʂTier 2 IR̍œKɂ͂Ȃ̎ԂARXgȂɂ͂BPython 3.13JITRpCftHgŖĂ̂́AƂɂRXgǂ̕ӂŃoX̂܂ʂĂȂ炩ȂBPython 3.14ł́A}VR[h̃nhỎPAR[h̕ỉPAœK̉PAJITRpCŎsoCgR[h̑Ȃǂ\肳ĂBIɂ͉炩̔fƂƂJITRpCLꂽnoꂷ͂B

@͂܂łɎグĂȂV@\̒‚𗎂EIɎグĂ\肾B

uPythonŐVLb`AbvṽCfbNX

uPythonŐVLb`Abvv

Copyright© Digital Advantage Corp. All Rights Reserved.

X|T[̂m点PR

ڂ̃e[}

Microsoft  WindowsőO2025
AI for GWjAO
[R[h^m[R[h Zg by IT - ITGWjArWlX̒SŊ􂷂gD
Cloud Native Central by IT - XP[uȔ\͂gD
VXeJmEnE yirzPR
Ȃɂ߂̋LPR

RSSɂ‚

ACeBfBAIDɂ‚

[}KWo^

IT̃[}KẂA AׂĖłBЃ[}KWwǂB