Python之父:讓 Python 速度快2倍

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"近日,在美國參加 PyCon 語言峯會的 Guido van Rossum 表示,必須讓 Python 語言的速度水平提高2倍,藉此與 C++ 等高性能編程語言正面對抗。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Core Python(CPython)的市場吸引力也證明了上述論斷,其出色的運行速度已經催生出 Pyston 等多種實現方案。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"正是由於天然性能不足,才讓 Python 語言更多在數據科學與機器學習領域得以施展——這類工作負載主要由 GPU 負責處理,因此抵消了大部分速度劣勢。當然,Python 也確實成就了 NumPy 以及 TensorFlow 機器學習框架等多種特定領域庫,建立起自己的數據科學與機器學習應用優勢。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"van Rossum 的雄心"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"上週,2021Python 語言峯會 PyCon 正式召開。在峯會上,van Rossum 在 GitHub 上發佈了一份文檔,詳盡介紹了自己提升 Python 速度表現的雄心壯志。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/ad\/ad8ec250b3b531c5dec8765952a15c52.jpeg","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在文檔中,他披露了“Shannon Plan”項目,承諾 4 年把 Python 速度提升 5 倍。並且在 Python 3.11 版本,實現 Python 速度提高2倍的目標。據悉,Python 3.11 是計劃於明年發佈 pre-alpha 版本的 Python 三個分支之一。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"閒不住的大牛"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"30 年前,由於對已有的編程語言感到十分失望,van Rossum 決定開發一門新語言——一門既易於使用功能又強大的語言。於是,Python 誕生了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前,Python 已經發展成世界上非常流行的編程語言,有無數開發者使用它處理大大小小的任務,特別是 Web 開發人員、數據科學家和系統管理員。並且,Python 也在一些世界知名的組織中扮演着關鍵角色,比如,Netflix 用 Python 向全球 1 億多戶家庭提供流媒體視頻,Instagram 用 Python 實現圖片分享,NASA 藉助 Python 來探索太空。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"去年 11 月,van Rossum 決定離開“退休”狀態重返工作,正式加盟微軟。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"而在退休前,他曾在 Dropbox 公司工作,並寫下了 400 萬行 Python 代碼。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"他坦言,“退休後,每天閒坐在家簡直無聊透頂”。爲此,他申請了微軟職位,並順利出任微軟傑出工程師這一實權職務。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對此,微軟也表現出自己對優秀人才的重視,允許他“自由選擇項目”,這也讓 van Rossum“再次回到自己熟悉的戰場”。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"van Rossum 寫道,“感謝微軟以這樣的方式回饋 Python 項目”。"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/87\/87d2b5238f3eeea86c77deac4dfb49c9.jpeg","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"微軟助力 Python 項目"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"據悉,微軟公司長期以來一直以多種方式爲 Python 項目提供助力,包括髮布免費的 Python 課程(微軟 Azure 雲 AI 服務教程的一部分)、通過 VS Code Python 擴展在 Windows 10 及以上版本支持 Python,併成爲 Python 項目的正式贊助商。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此外,微軟自 2006 年起開始成爲 Python 軟件基金會(PSF)的贊助商,並在今年提供了 15 萬美元資助。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"van Rossum 表示,微軟還資助了一支小型 Python 團隊“負責語言解釋層面的性能改進工作”。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前,微軟共有五位專爲 CPython 開發做出貢獻的核心成員,分別爲 Brett Cannon、Steve Dower、Guido van Rossum、Eric Snow 以及 Barry Warsaw,他們也都是 Python 核心開發者社區中的資深人士。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"微軟在今年 4 月發表聲明,提到 Eric Snow 一直在通過子解釋器研究 Python 語言中的多線程性能。自 Python 3.5 版本開始,Steve Dower 出任 build 管理員,同時也是 Windows 平臺的 CPython 專家。Barry Warsaw 則身爲 Python 指導委員會成員、Python 安全響應小組成員併爲 Python 版本管理器做出了貢獻。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"並且,隨着近期軟件供應鏈攻擊受到整個技術社區的高度關注,微軟還將重點放在保護主程序包 repo PyPI(即 Python Package Index)身上。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"微軟公司 Python 與 AI 工具首席經理 Dan Taylor 提到,“作爲 PSF 15 萬美元財務贊助中的一部分,我們將把資金集中到程序包工作小組當中,幫助他們進一步改善 PyPI 與程序包生態系統。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"“面對近期持續湧現的安全漏洞,我們與 Python 社區已經意識到建立可依賴供應鏈的重要意義,我們也很高興能爲這項長期改進做出切實貢獻。”"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"van Rossum 對一些問題的迴應"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前,van Rossum 也指出他和其他微軟同事將攜手核心 Python 開發人員推進公開貢獻,目前正專注於對 CPython 進行增量式變更。之所以暫時不進行重大變更,是爲了避免開發者們再次經歷由 Python 2.x 遷移至 Python 3 的痛苦經歷。整個遷移過程持續達十年之久,也給 Python 的羣衆基礎造成不小的影響。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"van Rossum 寫道,“如果分叉 \/ 分支不能長期存在,就不會有激動人心的 pull 產出。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"他還強調,“我們將繼續負責維護與支持工作……所有討論細節都將公開發布在 GitHub repo 當中。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"有部分資深人士認爲 Python 的解釋器及其 C 語言應用程序二進制接口(ABI)與應用程序協議接口(API)阻礙了 Python 在瀏覽器環境下的創新空間,van Rossum 也就此做出了迴應。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"“首先不能破壞穩定 ABI 的兼容性;其次不能破壞有限 API 的兼容性;第三不能破壞或拖慢極端用例。總之,代碼的可維護性纔是第一要務。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但核心 Python 項目是不是真能在 3.11 版本中將速度順利加倍?van Rossum 好像心裏也沒底,所以在說明中給自己留了點後路。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/2e\/2e4cb74342139f13bdaa7e9921fba70a.jpeg","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"他寫道,“我們還沒法確定 2 倍速度的目標能不能實現。但樂觀一點、好奇一點總沒有錯。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"而且他還大開腦洞,提出了在 Python 3.11 版本之後進一步將速度提高 5 倍的思路,並強調“我們必須保持旺盛的創造力。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"他提到,此次圍繞性能展開的 Python 變更,將主要服務於那些“運行 CPU 密集型純 Python 代碼”的開發者以及採用內置 Python 的網站客戶。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但對於大家使用 C 語言編寫的代碼(例如 NumPy 與 TensorFlow)、I\/O 綁定代碼、多線程代碼以及算法代碼,此次升級的效果就非常有限了。"}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章