Last Comment Bug 727960 - Incremental builds for mobile are too slow
: Incremental builds for mobile are too slow
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: Build Config (show other bugs)
: unspecified
: x86 Mac OS X
: -- normal (vote)
: mozilla13
Assigned To: Mike Hommey [:glandium]
:
: Gregory Szorc [:gps]
Mentors:
Depends on:
Blocks: 748452 748797
  Show dependency treegraph
 
Reported: 2012-02-16 12:25 PST by Benoit Girard (:BenWa)
Modified: 2012-04-25 08:37 PDT (History)
10 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
When extracting libraries, reuse cached library if it is newer than the apk (7.36 KB, patch)
2012-02-21 01:26 PST, Mike Hommey [:glandium]
taras.mozilla: review+
Details | Diff | Splinter Review
part 2 - Don't set MOZ_LINKER_CACHE if it was already set (1.33 KB, patch)
2012-02-22 05:33 PST, Mike Hommey [:glandium]
mark.finkle: review+
Details | Diff | Splinter Review

Description Benoit Girard (:BenWa) 2012-02-16 12:25:09 PST
I managed to get incremental cpp builds to <20 seconds by doing the following:

Patch APKOpen.cpp:
-  xul_handle = __wrap_dlopen("libxul.so", RTLD_GLOBAL | RTLD_LAZY);
+  xul_handle = __wrap_dlopen("/data/libxul.so", RTLD_GLOBAL | RTLD_LAZY);

(Do a full rebuild)

Once that is done you can modify a cpp file, rebuild using the objdir method, relink, copy and strip libxul.so and adb push to /data/libxul.so:

incremental_build.sh gfx (Does objdir build on gfx + relink)
cp ../builds/obj-fennec/toolkit/library/libxul.so . && /home/bgirard/mozilla/android/android-ndk-r5c/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-strip libxul.so
adb push libxul.so /data/libxul.so

With gold installed this makes the turn around time very fast. Can we get this patched in properly with a supported way to trigger it?
Comment 1 Ted Mielczarek [:ted.mielczarek] 2012-02-16 12:28:08 PST
Specifically what I was suggesting was a way to disable our internal linker, so that he could just rebuild libxul and push it to the device.
Comment 2 Benoit Girard (:BenWa) 2012-02-16 12:33:40 PST
I don't fully understand our linker/elfhack magic that happens on the device but being able to push libxul.so to the device is exactly what I need.
Comment 3 Mike Hommey [:glandium] 2012-02-16 23:09:24 PST
Would it work for you if make package was simply faster? IIRC, mounir filed a bug for that.
Comment 4 Benoit Girard (:BenWa) 2012-02-17 06:54:37 PST
If we can get the package step down to 1-2 seconds it would be better then this, otherwise this method makes the package step not needed thus free. When rebuilds are in the 20 second range each second is very valuable.
Comment 5 Mike Hommey [:glandium] 2012-02-17 10:30:26 PST
(In reply to Benoit Girard (:BenWa) from comment #0)
> I managed to get incremental cpp builds to <20 seconds by doing the
> following:
> 
> Patch APKOpen.cpp:
> -  xul_handle = __wrap_dlopen("libxul.so", RTLD_GLOBAL | RTLD_LAZY);
> +  xul_handle = __wrap_dlopen("/data/libxul.so", RTLD_GLOBAL | RTLD_LAZY);
> 
> (Do a full rebuild)
> 
> Once that is done you can modify a cpp file, rebuild using the objdir
> method, relink, copy and strip libxul.so and adb push to /data/libxul.so:

Note that starting fennec with the debug intent (see how on the wiki), the library is extracted to and loaded from /data/data/org.mozilla.fennec_$user/cache. With the new linker, it's overwritten each time you start, but with the old linker (export MOZ_OLD_LINKER=1 in mozconfig), it's not if the file in the cache directory is newer than the apk. So currently, if you build with MOZ_OLD_LINKER=1 and start with the debug intent, you should be able to adb push libxul.so /data/data/org.mozilla.fennec_$user/cache and have the same behaviour as the one you want.
You can also change the cache directory if you change the MOZ_LINKER_CACHE environment variable, which is set in the java code.

So if making make package fast is not good enough for you, we could:
- make the new linker do the same as the old linker wrt timestamps
- make it easier to override MOZ_LINKER_CACHE (iirc you need root to write in /data/data/org.mozilla.fennec_$user/cache)
Comment 6 Benoit Girard (:BenWa) 2012-02-17 12:34:02 PST
That would be wonderful, something simple we can roll into a script.
Comment 7 Mike Hommey [:glandium] 2012-02-21 01:26:54 PST
Created attachment 599066 [details] [diff] [review]
When extracting libraries, reuse cached library if it is newer than the apk

This also does some cleanup in the code.
Comment 8 Mike Hommey [:glandium] 2012-02-21 01:35:44 PST
(In reply to Mike Hommey [:glandium] from comment #5)
> So if making make package fast is not good enough for you, we could:
> - make the new linker do the same as the old linker wrt timestamps

The patch I attached implements this.

> - make it easier to override MOZ_LINKER_CACHE (iirc you need root to write
> in /data/data/org.mozilla.fennec_$user/cache)

I'll leave that to people who know Android APIs. This could also be done in a separate bug, whatever suits you best. Maybe the patch here is enough for you, Benoit ?
Comment 9 Benoit Girard (:BenWa) 2012-02-21 07:44:55 PST
So if I understand correctly I can set MOZ_LINKER_CACHE=/sdcard/data and push an updated+striped libxul.so there?
Comment 10 Mike Hommey [:glandium] 2012-02-21 07:54:13 PST
(In reply to Benoit Girard (:BenWa) from comment #9)
> So if I understand correctly I can set MOZ_LINKER_CACHE=/sdcard/data and
> push an updated+striped libxul.so there?

Java code is going to override MOZ_LINKER_CACHE, so not directly (which is why there is the second point). But you can push a libxul.so in /data/data/org.mozilla.fennec_$USER/cache, as long as you start with the debug intent (am start -a org.mozilla.gecko.DEBUG ...)
Comment 12 Mike Hommey [:glandium] 2012-02-22 05:33:15 PST
Created attachment 599579 [details] [diff] [review]
part 2 - Don't set MOZ_LINKER_CACHE if it was already set

With this patch, starting with:
am start -a org.mozilla.gecko.DEBUG -n org.mozilla.fennec_mh/.App --es env0 MOZ_LINKER_CACHE=/data/local/tmp

does what Benoit wants. Note that using /sdcard wouldn't work because you can't map executables from there.
Comment 13 Ed Morley [:emorley] 2012-02-22 10:26:20 PST
https://hg.mozilla.org/mozilla-central/rev/1419f0146049
Comment 15 Richard Newman [:rnewman] 2012-02-23 18:55:22 PST
https://hg.mozilla.org/mozilla-central/rev/b2e2e371842c
Comment 16 Benoit Girard (:BenWa) 2012-04-17 12:05:33 PDT
I made some time to try it out now that the debug intent got fix with no luck :(

cp ../builds/obj-fennec/toolkit/library/libxul.so /tmp/libxul.so && arm-eabi-strip /tmp/libxul.so && adb push /tmp/libxul.so /data/local/tmp/libxul.so

shell@android:/ $ ls -l /data/local/tmp                                        
-rwxrwxrwx shell    shell      358026 2012-01-19 12:41 gdbserver
-rwxrwxrwx shell    shell    18595804 2012-04-17 15:02 libxul.so

adb shell am start -a org.mozilla.gecko.DEBUG -n org.mozilla.fennec_bgirard/.App --es env0 MOZ_LINKER_CACHE=/data/local/tmp
Comment 17 Mike Hommey [:glandium] 2012-04-17 13:49:43 PDT
Since then, the debug intent doesn't trigger extraction. So you need to add another variable: MOZ_LINKER_EXTRACT=1 (with --es env1)
Comment 18 Benoit Girard (:BenWa) 2012-04-17 14:28:09 PDT
It works now. However having to launch fennec from command line is a big pain. Accidentally starting the program from the icon will get the old configuration so it's prone to errors :(.

Note You need to log in before you can comment on or make changes to this bug.