Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Opcodeを読んでいたら何故かphp-srcを読んでいた話
Search
むらおか
December 21, 2024
Technology
0
400
Opcodeを読んでいたら何故かphp-srcを読んでいた話
むらおか
December 21, 2024
Tweet
Share
Other Decks in Technology
See All in Technology
[JAWS-UG栃木]地方だからできたクラウドネイティブ事例大公開! / jawsug_tochigi_tachibana
biatunky
0
130
トレードオフスライダーにおける品質について考えてみた
suzuki_tada
3
180
教師なし学習の基礎
kanojikajino
4
350
re:Invent Recap (January 2025)
scalefactory
0
340
CNAPPから考えるAWSガバナンスの実践と最適化
nrinetcom
PRO
1
330
Redmineの意外と知らない便利機能 (Redmine 6.0対応版)
vividtone
0
190
private spaceについてあれこれ調べてみた
operando
1
160
Autify Company Deck
autifyhq
2
41k
2週に1度のビッグバンリリースをデイリーリリース化するまでの苦悩 ~急成長するスタートアップのリアルな裏側~
kworkdev
PRO
8
6.5k
AWSエンジニアに捧ぐLangChainの歩き方
tsukuboshi
0
220
DevSecOps入門:Security Development Lifecycleによる開発プロセスのセキュリティ強化
yuriemori
0
230
ドメイン駆動設計によるdodaダイレクトのリビルド実践 / Rebuild practice of doda direct with domain-driven design
techtekt
0
580
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
51
7.4k
Agile that works and the tools we love
rasmusluckow
328
21k
A Philosophy of Restraint
colly
203
16k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Optimizing for Happiness
mojombo
376
70k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
20
2.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
39
1.9k
Embracing the Ebb and Flow
colly
84
4.5k
A Tale of Four Properties
chriscoyier
157
23k
Transcript
Opcodeを読んでいたら 何故かphp-srcを読んでいた話 むらおか @muraSHOTARO PHP Conference Japan 2024
intの型キャストとintval関数 • (int) “1234” と intval(“1234”) • 文字列を整数にする
intの型キャストとintval関数 • (int) “1234” と intval(“1234”) • 文字列を整数にする なにが違う?
php-srcを読んでみよう!
C言語わからない。。。
php-srcの前にOpcodeを読むと良いらしい • OpcodeはPHPファイルを解析して生成される中間コード • PHP実行時に内容を出力することができる
Opcodeを読んでみよう!
intval (int)
intval (int)
関数の呼び出しの場合 • INIT_FCALL • DO_ICALL
• いくつかの関数がOpcodeのコンパイル時に最適化されるようになった ◦ intvalもそのうちの1つ (>=7.1.0) • Opcodeのコンパイルは zend_compile_* 関数で行われる ◦
https://wiki.php.net/rfc/abstract_syntax_tree#compiler_implementation AST導入とOpcodeの最適化
• いくつかの関数がOpcodeのコンパイル時に最適化されるようになった ◦ intvalもそのうちの1つ (>=7.1.0) • Opcodeのコンパイルは zend_compile_* 関数で行われる ◦
https://wiki.php.net/rfc/abstract_syntax_tree#compiler_implementation AST導入とOpcodeの最適化 zend_compile_* を探そう!
php-srcを読んでみよう!
zend_compile.c を読む • zend_try_compile_special_func ◦ intvalは特別な関数 https://github.com/php/php-src/blob/php-7.1.0/Zend/zend_compile.c#L3664
zend_compile.c を読む • zend_compile_func_cast ◦ ZEND_CASTにコンパイルされる https://github.com/php/php-src/blob/php-7.1.0/Zend/zend_compile.c#L3395
intval (int) Opcodeが 最適化されてる
• Opcodeリーディングはphp-srcを読む糸口になる • C言語を読むのに抵抗がある人でもOpcodeなら読みやすいかも? まとめ
• Opcodeリーディングはphp-srcを読む糸口になる • C言語を読むのに抵抗がある人でもOpcodeなら読みやすいかも? まとめ Opcodeから始めよう!
ありがとうございました!
https://wiki.php.net/rfc/abstract_syntax_tree https://qiita.com/tadsan/items/d11229761504c8a1ca81 https://speakerdeck.com/yasuaki640/phpnoopcodewo-du-ndemiyou https://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/ 参考資料