TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How Python bytecode is executed

179 点作者 r4victor超过 4 年前

5 条评论

r4victor超过 4 年前
Hi! This is part 4 of my Python behind the scenes series. The goal of this post is to understand how the CPython VM executes Python bytecode. You&#x27;ll learn:<p><pre><code> - what is the evaluation loop and how it&#x27;s implemented - when and how a thread may stop executing the bytecode to release the GIL - how CPython computes things - how CPython handles exceptions and implements statements like try-except, try-finally and with </code></pre> I appreciate your feedback! Thanks!
评论 #25038870 未加载
评论 #25039722 未加载
评论 #25037770 未加载
fulafel超过 4 年前
Would the loop be amenable to speedups from parallel execution? Some kind of parallel idempotent run ahead version of the loop might at least prime caches and resolve some dynamic dispatch stuff in advance. A bit like runahead execution in cpu design.
评论 #25041486 未加载
评论 #25042146 未加载
评论 #25040137 未加载
DonaldFisk超过 4 年前
&gt; The UNARY_NEGATIVE opcode pops value from the stack, negates it and pushes the result.<p>Why not have a top of stack register? Then all you need to put in your case statement (naively) is<p><pre><code> tos = -tos; </code></pre> thereby avoiding a pop and a push. In a virtual machine for a dynamically typed language such as Python, you&#x27;ll need to handle different types, and for a statically typed language you&#x27;ll need separate instructions for int and float, but in any case you avoid the pop and push. If the instruction takes more than one item from the stack, you at least have one fewer pop.<p>Incidentally, Burroughs mainframes were hardware stack machines and had two top of stack registers, A and B.
评论 #25040271 未加载
评论 #25043353 未加载
kzrdude超过 4 年前
This is where &quot;we&quot; (in general) want to improve CPython for performance - a jit, or a faster interpreter would be interesting. Anyone have ideas about this? Pyston 2 seems to use dynasm, and then there&#x27;s the core developer Mark who is proposing a paid project to speed up Python - he hasn&#x27;t revealed what he has implemented yet.
评论 #25041805 未加载
g42gregory超过 4 年前
This looks like a great resource. I always wanted to know how CPython is implemented.