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
RMagick, migrate to ImageMagick 7 #RubyKaigi #R...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Watson
April 18, 2019
Programming
10k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RMagick, migrate to ImageMagick 7 #RubyKaigi #RubyKaigi2019
Watson
April 18, 2019
More Decks by Watson
See All by Watson
クラウドネイティブ時代に 進化し続けるFluentd
watson
0
27
Magick
watson
0
12k
Improve JSON Performance
watson
2
1.1k
fastlane 奮闘記
watson
0
96
How to optimize Ruby internal.
watson
3
3.1k
iOS、AndroidアプリをRubyで
watson
1
510
RubyMotion 2.0
watson
6
2.8k
Differences CRuby/MacRuby/RubyMotion
watson
5
5.8k
Other Decks in Programming
See All in Programming
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
190
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
160
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
霧の中の代数的エフェクト
funnyycat
1
320
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
270
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
840
共通化で考えるべきは、実装より公開する型だった
codeegg
0
180
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.3k
act1-costs.pdf
sumedhbala
0
200
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.8k
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
140
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
440
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
330
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
Chasing Engaging Ingredients in Design
codingconduct
0
230
The World Runs on Bad Software
bkeepers
PRO
72
12k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Ruling the World: When Life Gets Gamed
codingconduct
0
280
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
360
Practical Orchestrator
shlominoach
191
11k
Transcript
RMagick, migrate to ImageMagick 7 Shizuo Fujita
self.inspect • @watson1978 • Ubiregi, Inc • Ruby committer •
RMagick maintainer
What's RMagick
"RMagick is an interface between the Ruby programming language and
the ImageMagick image processing library."
Active members ˏmockdeep ˏwatson1978 ˏdlemstra
My Motivation
I want to use Ruby ... •Web programming
I want to use Ruby ... •Web programming •iOS programming
I want to use Ruby ... •Web programming •iOS programming
•Image processing
I want to use Ruby ... •Web programming •iOS programming
•Image processing •Machine learning, etc
I want to use Ruby ... •Web programming •iOS programming
•Image processing •Machine learning, etc To meet crazy great people at Ruby World
Current Status of RMagick
None
Fixed major problems since v2.16.0 •Set up •Memory leaks •SEGVs
Set up problems
Set up problems •macOS (Homebrew) •Windows
macOS (Homebrew)
macOS (Homebrew)
Windows •Ruby has some environments • MingW • MSWin •
Cygwin • Windows Subsystem for Linux
Windows •Ruby has some environments • MingW • MSWin •
Cygwin • Windows Subsystem for Linux
MingW...?
Set up : MingW
Solution https://github.com/oneclick/rubyinstaller2/wiki/For-gem-developers
MingW works
MSWin...?
Set up : MSWin
MSWin supported...? Looks like MSWin supporting code...
Not supported... Why !? For MSWin
MSWin works well
Memory leak
Fixed many memory leaks 55 Closed
Case 1 VALUE Image_shear(VALUE self, VALUE x_shear, VALUE y_shear) {
Image *image, *new_image; ExceptionInfo *exception; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); new_image = ShearImage(image, NUM2DBL(x_shear), NUM2DBL(y_shear), exception); rm_check_exception(exception, new_image, DestroyOnError); (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); }
VALUE Image_shear(VALUE self, VALUE x_shear, VALUE y_shear) { Image *image,
*new_image; ExceptionInfo *exception; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); new_image = ShearImage(image, NUM2DBL(x_shear), NUM2DBL(y_shear), exception); rm_check_exception(exception, new_image, DestroyOnError); (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } Case 1 Allocate memory
VALUE Image_shear(VALUE self, VALUE x_shear, VALUE y_shear) { Image *image,
*new_image; ExceptionInfo *exception; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); new_image = ShearImage(image, NUM2DBL(x_shear), NUM2DBL(y_shear), exception); rm_check_exception(exception, new_image, DestroyOnError); (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } Case 1 Allocate memory Destroy memory
VALUE Image_shear(VALUE self, VALUE x_shear, VALUE y_shear) { Image *image,
*new_image; ExceptionInfo *exception; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); new_image = ShearImage(image, NUM2DBL(x_shear), NUM2DBL(y_shear), exception); rm_check_exception(exception, new_image, DestroyOnError); (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } Case 1 Allocate memory Destroy memory Raise exception with unexpected value
VALUE Image_shear(VALUE self, VALUE x_shear, VALUE y_shear) { Image *image,
*new_image; ExceptionInfo *exception; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); new_image = ShearImage(image, NUM2DBL(x_shear), NUM2DBL(y_shear), exception); rm_check_exception(exception, new_image, DestroyOnError); (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } Case 1 Allocate memory Destroy memory Raise exception with unexpected value Unreachable by exception
Case 1: Exception causes Memory Leak image = Magick::Image.read('sample.png').first begin
image.shear('x', 'y') rescue end
Case 2 static VALUE has_attribute(VALUE self, MagickBooleanType....[snip]) { Image *image;
ExceptionInfo *exception; MagickBooleanType r; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); r = (attr_test)(image, exception); CHECK_EXCEPTION() return r ? Qtrue : Qfalse; }
static VALUE has_attribute(VALUE self, MagickBooleanType....[snip]) { Image *image; ExceptionInfo *exception;
MagickBooleanType r; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); r = (attr_test)(image, exception); CHECK_EXCEPTION() return r ? Qtrue : Qfalse; } Case 2 Allocate memory
static VALUE has_attribute(VALUE self, MagickBooleanType....[snip]) { Image *image; ExceptionInfo *exception;
MagickBooleanType r; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); r = (attr_test)(image, exception); CHECK_EXCEPTION() return r ? Qtrue : Qfalse; } Case 2 Allocate memory Missing destroy
Case 2: Missing destroy lead to Memory Leak image =
Magick::Image.read('sample.png').first image.gray?
Case 3 Unnecessary clone API returns NEW image in allocated
memory
Case 3: Memory Leak by incorrect API usage image =
Magick::Image.read('sample.png').first image.sharpen_channel
Case 4
Case 4 Found memory leak in ImageMagick
Case 4
Case 4: Huge software has Memory Leak
How to detect memory leak
Profiler tool
Profiler tool Memory leak detected
Profiler tool
Profiler tool... •Detects at executed code only •unit-test •RSpec •Needs
better coverage...
Code reading... •To find same pattern that profiler detects
SEGV
Closed 5 SEGVs 4 Fixed 1 Workaround
Workaround Case Help wanted
Workaround Case •Call back image processing progress to Ruby User's
Ruby code RMagick ImageMagick Callback
ruby_stack_length() shows 51119378542 = 47 GB • Invalid stack length
• GC running →SEGV
RMagick is better than ever.
Future...
ImageMagick 7 support
Preparing draft code... now
Plan 1: Split RMagick ver 4.x RMagick ver 3.x ver
3.0 ver 3.1 ver 2.16.1 ImageMagick 7 ImageMagick 6
Plan 2 : Mix both ImageMagick 7 ImageMagick 7 ImageMagick
6 Using many #if defined ...
Plan 3: Bundle both ImageMagick 7 ImageMagick 6
We welcome good ideas for the future
Announcement •RubyData Workshop (Tomorrow, 14:20 ~) •RubyKaigi 2019 Code Party
(Tomorrow, 19:00 ~)
Thank you