
Redex: an Android bytecode optimizer developed by Facebook - folz
http://fbredex.com/
======
donnfelker
I'm happy that FB is releasing these tools. I really am, but you know what I
want? I want to use the FB app with out it DESTROYING my phone's usability.
Anytime FB is installed on any of my devices, the device degrades day after
day until the phone is virtually unusable. Next step: Uninstall Facebook.
Phone is usable again. I only use Nexus devices with a lot of space on them,
so ... it's not like I'm using a cheap burner.

Unfortunately, due to this problem, I've been using the FB mobile website for
a very long time. Every 3-6 months I'll re-install the FB Android app in hopes
that things are better, only to be let down once again.

Something tells me that all this bit flipping that FB is doing is not making
things better, but worse. Sure, it may be better for the FB app, but worse for
the device general. This is just my speculation at this point though ...

~~~
incepted
Agreed.

I think the Facebook engineers have a tendency to fix symptoms rather than
causes. A lot of their engineering creations are trying to shrink the binary
while they might want to consider revisiting all the dependencies that their
application depends on, because that graph (and the size of their apk) is
really absurdly large for such an app.

Of course, there's also the fact that such a tool is already partially
obsolete because of Jack and Jill.

------
takno
It's honestly pretty difficult to believe that any kind of optimization has
taken place on the Facebook app. I don't have the time or the bandwidth to
keep up with the updates

~~~
Ambroos
It is indeed out of control. They have so much stuff in their app that an
update takes over 2 minutes to run on Marshmallow on a total high-end device
(Snapdragon 810). No other app comes even close to taking that long to
precompile for ART.

Which is surprising really, considering their Messenger app is excellent, fast
and lean.

------
bertr4nd
Hey all, ReDex developer here, happy to answer questions!

~~~
jevinskie
How are you handling the Gradle experimental plugin and Jack/Jill (no problems
because you operate at dex level?)? I heard Proguard and other class/dex
transformations were having trouble adopting the new model. Supposedly Google
is working on adding extension points to the API.

~~~
bertr4nd
We should work fine with Jack & Jill since, as you said, we work at the dex
level. That said, it'll be interesting to see how our optimizations interact.

------
wnevets
I am assuming the facebook app doesn't use this?

~~~
bertr4nd
Yes, of course we do! It's the motivating example for ReDex :-)

~~~
Yhippa
I think you missed the joke.

~~~
bertr4nd
My next invention will be a sarcasm detector.

~~~
fit2rule
Maybe you could stop inventing things and .. you know .. make your software
better for the end user. The Facebook app is one of the most hated apps in my
household, and we've all stopped using it.

~~~
andrewingram
Yes, it's a well-known fact that everyone contributing to a piece of software
is working on the same problem and that multiple problems can't be worked on
in parallel.

~~~
fit2rule
He is working on the very problem we need him to work on. I'm telling him to
get back to work and stop dorking around on HN, because there is tons, and
tons, more work to do - and I fail to see how HN is anything but a distraction
for someone working on this issue.

~~~
piyush_soni
No one can work all day like a machine. Everyone needs some healthy
distractions to a reasonable limit.

~~~
fit2rule
How often do you get to complain directly to an author of a technology you
consider to be highly disruptive in your local environment?

------
yincrash
Debugging a crash report from an app with both proguard and redex sounds like
it would be a nightmare.

~~~
AstralStorm
Both Proguard and ReDex can be coaxed to unmangle names (produces a special
file and has a tool to decode mangled traces)

They don't really do any major optimizations - they're not a real SSA/CSE/eta-
form optimizer, like what llvm does to its bytecode.

------
nickmain
Unfortunate name collision: [https://redex.racket-
lang.org](https://redex.racket-lang.org)

~~~
ori_b
It's also a well known term in programming language theory:
[https://www.classes.cs.uchicago.edu/archive/2002/winter/CS33...](https://www.classes.cs.uchicago.edu/archive/2002/winter/CS33600/slides/Lesson2.pdf)

------
mwcampbell
How does this compare to ProGuard?

~~~
bertr4nd
It's conceptually similar, but we've focused on optimizations that add value
on top of ProGuard - we do use ProGuard internally, so the improvements we're
seeing from ReDex are on top of that.

We get a lot of leverage out of operating on dex directly, as the final step
in the build. For instance we can make really good inlining decisions because
we know how many virtual registers the caller and callee use.

~~~
amolgupta
Do I need to care about any more configurations when using it along with
proguard? Like extra lines in proguard.txt or change of mapping files when
uploading to my crash reporting tools?

~~~
bertr4nd
You shouldn't need to change your proguard config to use redex. For mapping
files, the one thing that can trip people up is that we strip out source file
names. After you run redex there should be a /tmp/filename_mappings.txt to do
the back-mapping, similar to proguard.

If you're using third-party crash reporting tools that don't understand that
back-map, though, you can always turn off the source stripping. We describe
how to do that here:
[https://github.com/facebook/redex/blob/master/docs/Config.md](https://github.com/facebook/redex/blob/master/docs/Config.md).

------
yinghau76
How can I integrate Redex with gradle building?

------
tananaev
On my Nexus 4 facebook app takes ages (a few minutes) to update/install. I
wonder if Redex "optimization" is the reason for that.

~~~
mckilljoy
Redex runs at compile time, not at install time.

~~~
tananaev
Yes, but it changes the byte code, and I think android compiles that code into
machine code when you install an app.

~~~
muricula
If anything it sounds like it would be faster because there is less byte code
which needs to be compiled.

Most likely the problem is the Facebook app has a lot of bytecode. That's
probably why the wrote redex in the first place, so they would have less
bytecode in their final APK.

~~~
tananaev
Any other app takes seconds to install. Facebook takes minutes. I can
understand some difference, but not that much.

~~~
karlding
There was a post on HN [0] a few years back about the Dalvik patch that
Facebook used for their Android app, due to the large number of methods [1]
the app had. This was causing issues on the older Gingerbread devices, so
their solution was to modify the internals of the Dalvik VM while it was
running their code to increase the buffer size.

[0]
[https://news.ycombinator.com/item?id=5321634](https://news.ycombinator.com/item?id=5321634)

[1] [https://www.facebook.com/notes/facebook-engineering/under-
th...](https://www.facebook.com/notes/facebook-engineering/under-the-hood-
dalvik-patch-for-facebook-for-android/10151345597798920/)

~~~
V-2
Which is borderline insane

------
haidrali
how many developers ( companies ) other then Facebook already using Redex or
any of these kinds of optimisations ?

------
yongjhih
redex as a docker container: [https://github.com/yongjhih/docker-
redex](https://github.com/yongjhih/docker-redex)

