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
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
62
JKでもわかるSFace Recognition
bigbackboom
0
80
Androidタブレットアプリ作成_棚から牡丹餅を得るにはまず棚から
bigbackboom
0
70
Proto Datastoreを使う前の心構え
bigbackboom
0
320
Have A Dog in CircleCI
bigbackboom
0
90
Androidエンジニアのお仕事でのショボーン
bigbackboom
0
94
解明!楽しいプレゼンする話すスキル
bigbackboom
0
130
Pay for Businessのgradle.ktsへの移行の小噺
bigbackboom
0
88
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
Everyday Curiosity
cassininazir
0
230
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
KATA
mclloyd
PRO
35
15k
The Pragmatic Product Professional
lauravandoore
37
7.3k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
780
Chasing Engaging Ingredients in Design
codingconduct
0
220
WCS-LA-2024
lcolladotor
0
640
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Speed Design
sergeychernyshev
33
1.9k
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