Python͈ȑO炻̎sx_ƂĂB傫P\JITRpCPython 3.13ł͎IɃT|[gꂽBꂪǂȂ̂Ă݂悤B
@OPython 3.13̐V@\VREPLƁAt[Xbh[hɂČB͎Iɒljꂽ@\łuJITRpCvɂČĂ݂悤B
@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
@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)}')
@M҂̎茳ɂ͊̃o[WPythonCXg[Ă̂ŁAgďLvOisample.pyjsĂ݂B
@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傴ςɍlA15̑xƂ邾낤B̂悤JITRpCɂsxシʂƂẮA[vœ̌^̃f[^xꍇ⓯xĂяoꍇȂǂB
@Python 3.11ȍ~łȂقǂ̍ȂƂƁAFaster CPythonƂvWFNgɂ̂B
@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[ĥɖ𗧂jBTier 2Tier 3̈Ⴂ́A\[X̏ɊWBzbgR[h͍ɎsׂłAJITRpC₻ɔœK̑ΏۂƂȂ邪A\[XߏɏȂƂlȂTier 2ŁAłȂTier 3ŎsiAPython 3.13œJITRpCTier 2ΏۂƂjB
@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
@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)
@sʂȉɎB
@ł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)
@sʂȉɎB
@̂悤Ƀ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
@ȉ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Ƃ́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
*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
Copyright© Digital Advantage Corp. All Rights Reserved.