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
Extended A Study in Bitmap: Is NDK the fast Pro...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
bigbackboom
October 15, 2024
34
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Extended A Study in Bitmap: Is NDK the fast Processing method by CPU?
bigbackboom
October 15, 2024
More Decks by bigbackboom
See All by bigbackboom
Learn as a Pair
bigbackboom
0
73
Not 2 L8 JKでもわかるMaterial 3
bigbackboom
0
60
JKでもわかるSFace Recognition
bigbackboom
0
80
Androidタブレットアプリ作成_棚から牡丹餅を得るにはまず棚から
bigbackboom
0
69
Proto Datastoreを使う前の心構え
bigbackboom
0
320
Have A Dog in CircleCI
bigbackboom
0
86
Androidエンジニアのお仕事でのショボーン
bigbackboom
0
94
解明!楽しいプレゼンする話すスキル
bigbackboom
0
120
Pay for Businessのgradle.ktsへの移行の小噺
bigbackboom
0
87
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
160
Designing Powerful Visuals for Engaging Learning
tmiket
1
400
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
300
Docker and Python
trallard
47
3.9k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
130
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Speed Design
sergeychernyshev
33
1.8k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
220
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
Statistics for Hackers
jakevdp
799
230k
A designer walks into a library…
pauljervisheath
211
24k
GitHub's CSS Performance
jonrohan
1033
470k
Transcript
EXTENDED A Study in Bitmap: Is NDK the Fastest Processing
Method by CPU? キクチコウダイ
自己紹介 菊池 広大(キクチコウダイ) 2023年6月 株式会社マネーフォワードに入社 埼玉出身、Iターンで東京から福岡に引越し Androidエンジニア、たまにバックエンド Github: https://github.com/BigBackBoom
WE ARE HIRING!!!!
概要 以前、モバチキで発表したものに 内容を肉付けしたものとなっています。
おさらい
概要 C++で実行されるAndroidのNDKは 本当に実行速度最速なのか? Bitmapファイルを処理して その速度を検証してみよう
NDKとは?
NDKとは? • Kotlin/JavaからC/C++などのNativeコードでの開発 が可能にするツールセット • C/C++でしか提供されていないパワフルなライブラリ が利用可能になる • Nativeコードのロジックを再利用できる。
検証内容
検証内容 4KのBMPファイルを アルファブレンディングして 処理時間を測る
パフォーマンス
パフォーマンス
パフォーマンス NDK: • Average: 50ms • Max: 75ms • Min:
33ms • Median: 45.5ms JVM: • Average: 63.3ms • Max: 90ms • Min: 59ms • Median: 60ms まとめ
結論 • NDKだから早いとは限らない • ただ、ハードウェアアクセラレーションを利用すれば最強! • とはいえ、【パフォーマンスチューニング】は大事だが、ゲームアプリ のフレームレート改善でもない限り、msレベルのチューニングは無駄
EXTENDED!
Extended なんでJVMとネイティブコードで そんなに処理速度に差が出てないの?
Extended JavaはJust in Time(JIT)コンパイラーを 内部的に利用しているため 実行直前にネイティブコードを生成している。
Extended ハードウェアアクセラレーションでの処理は 果たして高速なのだろうか? OpenGL© ESで試してみた
Extended • クロスプラットフォームで動作するグラフィックライ ブラリ。 • 実装難易度は高いが、最高レベルのパフォーマンスで 描画可能 • Androidの描画ライブラリSkiaも裏はこいつ
Extended OpenGLのテクスチャに画像を貼り付けて シェーダーで高速 ブレンディング処理を実施する
Extended • テクスチャの色データを取 り出す GLSLの実装 #version 300 es precision mediump
float; in vec2 v_texCoord; layout(location = 0) out vec4 outColor; uniform sampler2D s_texture; uniform vec3 rgb; uniform float alpha; void main() { // change color order since bitmap is BGR float filtering = 1.0 - alpha; vec4 texture = texture(s_texture , v_texCoord); float r = (texture.b * alpha) + (rgb.r * filtering) ; float g = (texture.g * alpha) + (rgb.g * filtering) ; float b = (texture.r * alpha) + (rgb.b * filtering) ; // change color order since bitmap is BGR outColor = vec4(r, g, b, 1.0f); }
Extended • テクスチャの色データを取 り出す • 取り出したデータでブレン ディング処理をする GLSLの実装 #version 300
es precision mediump float; in vec2 v_texCoord; layout(location = 0) out vec4 outColor; uniform sampler2D s_texture; uniform vec3 rgb; uniform float alpha; void main() { // change color order since bitmap is BGR float filtering = 1.0 - alpha; vec4 texture = texture(s_texture , v_texCoord); float r = (texture.b * alpha) + (rgb.r * filtering) ; float g = (texture.g * alpha) + (rgb.g * filtering) ; float b = (texture.r * alpha) + (rgb.b * filtering) ; // change color order since bitmap is BGR outColor = vec4(r, g, b, 1.0f); }
Extended • テクスチャの色データを取 り出す • 取り出したデータでブレン ディング処理をする • 普通のプログラミング言語 に近いが、if文を使うと劇
的に遅くなる😂 GLSLの実装 #version 300 es precision mediump float; in vec2 v_texCoord; layout(location = 0) out vec4 outColor; uniform sampler2D s_texture; uniform vec3 rgb; uniform float alpha; void main() { // change color order since bitmap is BGR float filtering = 1.0 - alpha; vec4 texture = texture(s_texture , v_texCoord); float r = (texture.b * alpha) + (rgb.r * filtering) ; float g = (texture.g * alpha) + (rgb.g * filtering) ; float b = (texture.r * alpha) + (rgb.b * filtering) ; // change color order since bitmap is BGR outColor = vec4(r, g, b, 1.0f); }
Extended
結論
結論 俺たちのGPUは最強なんだ!
結論 • Javaも実は実処理はネイティブコード • GPUを使った処理はやっぱり早い。
以上、ありがとうございました!
Sample Repository: ❖ Kotlin 2.0 ❖ Multi-Module with NDK ❖
Jetpack Compose https://github.com/BigBackBoom/hades