Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Redex: an Android bytecode optimizer developed by Facebook (fbredex.com)
107 points by folz on April 12, 2016 | hide | past | favorite | 56 comments


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 ...


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.


I've never been comfortable with the FB app phoning home so I too use the mobile website. The thing about it is that the text fields don't work well at all. Slow response times, no way to go back and correct my errors without erasing everything, and repetition of words. Over the years and across browsers the issues change but they've never worked like most other text fields on mobile websites. I wish I knew what they were doing to make them behave so poorly.


I'm guessing it has so much old "legacy" code long before all this new cool inventions like React Native etc. were invented.

I wonder why they cannot start from scratch a new one which has a better architecture and does not slow down your phone.


I've actually got to sit down and debug my Nexus 5. I don't run the FB app but it's degrading in the same kind of way. No real easy cause that I can see. I'm hoping adb can shed some light for me.


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


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.


I uninstalled it as well, and noticed that the mobile website for facebook is much better in performance than the so called 'native' app.


Stopped using it and never looked back (as they say). Battery life much improved and more time for other more productive social mediums.


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


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.


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.


Thanks for sharing, do you still see runtime performance benefits when ART is used or just compilation / dex2oat perf improvement?


Yep, we actually see perf benefits overall with ART. Starting with redex-optimized bytecode actually helps dex2oat generate faster/smaller native code.


Excellent, I look forward to trying this out!


Does Jack and Jill fuck your shit up?


Lol.

Actually I'm pretty interested to see what we can do with jack, since it has an API to hook into various stages of the code generation pipeline. We haven't invested much time in it yet though, since it's still in a somewhat experimental phase. Looking forward to investigating it more, though.


Can you provide any numbers on the results of these optimisations? They seem to be missing from the website and blog post.


I didn't see any performance numbers in the blogpost. Do you plans to share some benchmarks ?


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


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


I think you missed the joke.


My next invention will be a sarcasm detector.


No ill will intended. I definitely have a hard time detecting sarcasm with my own friends in group chat. Very impressed by this project BTW.


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.


Goodness, give him a break. It's not like they aren't trying to do something about it.


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.


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.


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


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


Woooosh.


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


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.


Unfortunate name collision: https://redex.racket-lang.org


It's also a well known term in programming language theory: https://www.classes.cs.uchicago.edu/archive/2002/winter/CS33...


How does this compare to ProGuard?


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.


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?


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.


How can I integrate Redex with gradle building?


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


Redex runs at compile time, not at install time.


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


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.


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


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

[1] https://www.facebook.com/notes/facebook-engineering/under-th...


Which is borderline insane


Their ios app has over 18000 classes (https://www.reddit.com/r/programming/comments/3h52yk/someone...), so I can easily believe the android app is similarly bloated as well. (To be fair, most of the 18K classes seem to be auto generated, but that still doesn't lessen the compiler's burden.)


I heard there are something like 400 mobile developers working on the FB apps. I don't know there's any way to keep a team that size from producing bloat with every revision.


That seems like a useful engineering problem for Facebook to try to solve, rather than this bullshit rocket science optimization stuff that adds yet more complexity for only incremental gains.


Compiler optimizations are not "bullshit rocket science optimization". You depend on them every day.

None of the optimizations in this tool are "rocket science" compared to the optimizations that GCC, for example, does.


Right, so on Android if you need code to be fast, write it in C++.

If you have a ridiculously bloated and buggy Java app, writing an optimizing compiler doesn't sound like the most effective solution.


My take: If you can't write it fast enough in Java, it is probably not a good mobile app candidate in the first place. The Dalvik optimizer and the JIT yield a regularly reasonable experience for me.


That is actually going away in Android N: http://developer.android.com/preview/api-overview.html#quick...


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


redex as a docker container: https://github.com/yongjhih/docker-redex




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: