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
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
400
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Building AI with AI
inesmontani
PRO
1
1.1k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.3k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
400
The World Runs on Bad Software
bkeepers
PRO
72
12k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
My Coaching Mixtape
mlcsv
0
140
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