Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Pythonで爆速でHello, World!する
Search
AnaTofuZ
May 24, 2025
Technology
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Pythonで爆速でHello, World!する
https://shingenpy.connpass.com/event/353887/
でのLTです
AnaTofuZ
May 24, 2025
More Decks by AnaTofuZ
See All by AnaTofuZ
Perl GraphQL 高速化バトル 2026年5月版
anatofuz
0
69
k1LoW/deckのすすめ
anatofuz
2
760
Perl1.0 Deep Drive 0.01
anatofuz
0
250
Rubyの国のPerlMonger
anatofuz
3
2.5k
思いつきで推しの誕生日記念コンテンツを2日で作る技術
anatofuz
0
210
AWSで雰囲気でつくる! VRChatの写真変換ピタゴラスイッチ
anatofuz
0
550
令和最新版 Perlコーディングガイド
anatofuz
5
11k
rakulangで実装する! RubyVM
anatofuz
6
6.2k
沖縄の大学で育った学生がエンジニアになるまで
anatofuz
2
8k
Other Decks in Technology
See All in Technology
Amazon Quick on DesktopがIAM Identity Centerで動かない理由
yukiogawa
0
190
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
4
1.7k
Minecraft JavaのMODをSwiftで作る
1mash0
0
160
20260912_スクフェス三河
kgnkhkr
0
380
Deployment の 先にある AI Agent 基盤 - kagent vNext、Agent Substrate、Hermes から読み解く Agent Runtime の現在地 / k8s-matsuri-2-ai-agent-platform-amsy810
masayaaoyama
3
550
Omarchy Quattro の日本語設定周り
simosako
2
180
2026_devsumi_ozono.pdf
o3
3
500
あるけみー式LTスライド作成術
alchemy1115
1
210
ユーザー価値を届け続けるためにウォンテッドリーが大切にしている文化
kotaminato
0
150
LTのテーマ どうきめてる?〜5つの型と私のやり方〜
yama3133
1
100
Claude in Chrome 入門 / Introduction to Claude in Chrome
cielo1985
0
800
AI 時代のスタートアップエコシステ厶から考究する技術的負債との向き合い方
m3m0r7
PRO
2
2k
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
3.2k
The Limits of Empathy - UXLibs8
cassininazir
1
670
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Evolving SEO for Evolving Search Engines
ryanjones
0
290
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
67
58k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
320
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Practical Orchestrator
shlominoach
191
12k
Darren the Foodie - Storyboard
khoart
PRO
4
3.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Transcript
Python で爆速でHello, World! する 八雲アナグラ(@AnaTofuZ) 2025/05/24 [Shingen.py] Python で学ぶKeycloak を用いた
ユーザー管理ハンズオン 1
pprint(self) 八雲アナグラ(@AnaTofuZ) 普段はRuby 、趣味でPerl 、たまにPython 使って ます 甲府でエンジニアっぽいイベント開催しようと してます Houtou.pm
( なんでも) Kofu.rb (Ruby) 好きなモジュールはBeautifulSoup4 です 2
Houtou.pm 来週のこの時間!! きてくれ!! サーバーレス使わずにVPS とCDN でアプリ組んだ場合のモダンな 構成について話します “ “ #houtoupm
では、純粋関数とワークフローオートメーションの蜜 月についてトークする予定です “ “ 3
️: Python でHello, World! したことあ るひと 4
Python でHello, World! 何かしらのエディタで開いて print("Hello, World!") 5
Python でHello, World! 完 6
Python で爆速でHello, World! する 7
Hello, World まで print("Hello,World") をpython が処理するまでにはいくつかのステ ップがある 字句解析 構⽂解析 VMが実⾏
Hello, World! 8
Hello, World まで 字句解析 print , Hello,World などのトークンに分解 構文解析 トークンの並びをPython
で意味があるデータに変換 実行 PythonVM が構文解析のデータを元に命令を実行 字句解析 構⽂解析 VMが実⾏ Hello, World! 9
Python の内部処理 print("Hello, World") は実際はこんな感じのPythonVM の命令にな る ❯ python -m
dis hello.py 0 0 RESUME 0 1 2 PUSH_NULL 4 LOAD_NAME 0 (print) 6 LOAD_CONST 0 ('Hello, world!') 8 CALL 1 16 POP_TOP 18 RETURN_CONST 1 (None) 10
改めて処理を確認すると いわゆる python のCPython は全部分がC で書かれている つまりPython のコードは実際はC で書ける Hello,
World! するだけなら別に構文解析とかする必要もない オブジェクトを作ってprint すればいいだけなので、PythonVM の 命令も短縮できるのでは 11
CPython をいじる CPython のメインルーチンで最初からC でPython の print("Hello,World!") を書く ️ 爆速
字句解析 構⽂解析 VMが実⾏ Hello, World! 12
爆速Hello, World! 専用Python を作る 1. https://github.com/python/cpython を git clone 2.
パッチを書く 3. ./configure デバッグしたいなら ./configure CFLAGS="-O0 -g" あたり 4. make -j 5. ./python して Hello, World! が出れば勝ち 13
起動時の状態で処理を切り分けている箇所にパッチをいれる static void pymain_run_python(int *exitcode) { ... pymain_header(config); _PyInterpreterState_SetRunningMain(interp); assert(!PyErr_Occurred());
if (config->run_command) { *exitcode = pymain_run_command(config->run_command); } else if (config->run_module) { *exitcode = pymain_run_module(config->run_module, 1); } else if (main_importer_path != NULL) { *exitcode = pymain_run_module(L"__main__", 0); } else if (config->run_filename != NULL) { *exitcode = pymain_run_file(config); } else { *exitcode = pymain_run_stdin(config); } pymain_repl(config, exitcode); goto done; 14
Hello, World! を用意する PyUnicode_FromString で文字列からPython のオブジェクトを作れる 今回は簡単のために文字列に直接改行文字をいれておく PyObject *py_str =
PyUnicode_FromString("Hello, World!\n"); if (py_str == NULL) { PyErr_Print(); Py_Finalize(); goto error; } 15
PyObject を書き込む PyObject_Print でC のファイルポインタにオブジェクトの内容を書 き込める stdout を指定してあげると print っぽくなる
int res = PyObject_Print(py_str, stdout, Py_PRINT_RAW); if (res < 0) { PyErr_Print(); goto error; } Py_DECREF(py_str); Py_Finalize(); 16
Python のI/O システムを使わずにstdout に書き込んでいる print 関数を厳密にエミュレートする場合は PyFile_WriteObject などのAPI でstdout に書き込むとよい
PyObject *sys_module = PyImport_ImportModule("sys"); if (sys_module == NULL) { goto error; } PyObject *stdout_obj = PyObject_GetAttrString(sys_module, "stdout"); if (stdout_obj == NULL) { ... goto error; } PyFile_WriteObject(py_str, stdout_obj, Py_PRINT_RAW); 17
ビルドすると... ❯ ./python Python 3.15.0a0 (heads/shingenpy-dirty:557ea496425, Jan 1 1980, 00:00:00)
[GCC 14.2.1 20250322] on linux Type "help", "copyright", "credits" or "license" for more information. Hello, World! 無事Hello,World! がでた!!! 18
まとめ python で Hello, World! した CPython のAPI 意外と怖くない 19