Closed Bug 760229 Opened 14 years ago Closed 14 years ago

Java UI gfx code cause lot of GC wakeups during content animations( video/css/webgl)

Categories

(Firefox for Android Graveyard :: General, defect)

x86_64
Android
defect
Not set
normal

Tracking

(firefox18 verified, blocking-fennec1.0 -, fennec15+)

VERIFIED FIXED
Firefox 18
Tracking Status
firefox18 --- verified
blocking-fennec1.0 --- -
fennec 15+ ---

People

(Reporter: romaxa, Assigned: kats)

References

()

Details

(Keywords: perf)

Attachments

(4 files, 2 obsolete files)

I noticed that while m-c native fennec rendering some fast animation it cause bunch of dalvikvm GC wakeups, with message: D/dalvikvm( 2545): GC_EXPLICIT freed 86K, 51% free 2667K/5379K, external 2398K/2652K, paused 162ms Looks like we are leaking some stuff in Java code which cause GC cleanup every 1-5 seconds.
blocking-fennec1.0: --- → ?
It's probably the bajillion viewport-related objects and JSON strings we use to keep the viewport information in sync.
Keywords: mlk
blocking-fennec1.0: ? → -
Depends on: 727352
tracking-fennec: --- → 15+
Ok, looks like it is not leak, but Java UI rendering/gfx code which does zillions of Rects and other objects allocations. 1) One thing, Java GFX code need more optimization, rects caching et.c. 2) Another thing is we should not repaint UI while gecko layer manager rendering animations/videos/webgl et.c. that is causing problem 1)
Keywords: mlk → perf
Summary: Java UI possibly leak some memory → Java UI gfx code cause lot of GC wakeups during content animations( video/css/webgl)
with this patch I have GC wakeups slowed from every 1 second -> 20 seconds between GC.
Should we be reviewing this patch?
Not really... this patch is just proto showing what is need to be fixed... but I guess someone who knows that code well should make rendering pipeline working without any GC-able allocations.. probably I can do that at some point, but not right now.
First part, take care about SingleTileLayer.draw rectangles,arrays
Assignee: nobody → romaxa
Attachment #629362 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #652802 - Flags: review?(bugmail.mozilla)
Here is part which optimizes Layer.getBounds call and using cached bounds rectangle. part1 + part2 - make dalvik GC firing every 11 seconds on nexus-7 (comparing to 5 seconds without patches), tested on http://learningwebgl.com/lessons/lesson05/index.html
Attachment #652823 - Flags: review?(bugmail.mozilla)
Comment on attachment 652802 [details] [diff] [review] SingleTileLayer paint code caching Review of attachment 652802 [details] [diff] [review]: ----------------------------------------------------------------- ::: mobile/android/base/gfx/SingleTileLayer.java @@ +67,5 @@ > + mCropRect = new Rect(); > + mCoords = new float[20]; > + } > + > + mViewport = context.viewport; This seems wrong. Just above this you do | mViewport = new RectF(); | which is thrown away here because you're now pointing mViewport to context.viewport. This should be mViewport.set(context.viewport) instead. @@ +73,5 @@ > if (repeats()) { > // If we're repeating, we want to adjust the texture bounds so that > // the texture repeats the correct number of times when drawn at > // the size of the viewport. > + mBounds = getBounds(context); Same thing here, I'd rather have this be mBounds.set(getBounds(context)) so that we don't throw away the mBounds that was created above. Or even better, add a second getBounds function which takes a RectF as a parameter and populates it. The existing RectF function can be implemented using the new one. @@ +80,5 @@ > } else if (stretches()) { > // If we're stretching, we just want the bounds and texture bounds > // to fit to the page. > + mBounds.set(context.pageRect); > + mTextureBounds = mBounds; Ditto, this should be mTextureBounds.set(mBounds) @@ +85,3 @@ > } else { > + mBounds = getBounds(context); > + mTextureBounds = mBounds; Same here. In fact now that I think about it probably makes sense to just initialize all of these "cache" fields in the constructor and make the fields final, that way you can't reallocate them.
Attachment #652802 - Flags: review?(bugmail.mozilla) → review-
Comment on attachment 652823 [details] [diff] [review] Optimize Layer.getBounds function Review of attachment 652823 [details] [diff] [review]: ----------------------------------------------------------------- ::: mobile/android/base/gfx/Layer.java @@ +73,5 @@ > + mLastZoomFactor = context.zoomFactor; > + mCachedBounds = RectUtils.scale(new RectF(mPosition), mLastZoomFactor / mResolution); > + mBoundsChanged = false; > + } > + return mCachedBounds; This returns a direct reference to a stored object, which means whoever calls this function can then mess with the object and have this function return corrupted data to other callers. I guess in practice this might not happen, but it's not a safe programming technique. I assume the problem here is just the object creation, which can be fixed if you pass in a RectF to be filled in, as I mentioned in the review comment for the other patch. Also if you add a version of RectUtils.scale which takes a RectF instead of a Rect you can remove the "new RectF" creation in this function.
Attachment #652823 - Flags: review?(bugmail.mozilla) → review-
Stealing this bug since I would like to see it land. I've updated this patch to address my comments on the previous version. Requesting review from Cwiiis since romaxa wrote the original patch and it doesn't seem right to get him to review it.
Assignee: romaxa → bugmail.mozilla
Attachment #652802 - Attachment is obsolete: true
Attachment #658627 - Flags: review?(chrislord.net)
This does the same for ScrollbarLayer, which showed up as the next-highest memory allocator class in ddms' allocation tracker (not exactly the most useful tool, but better than nothing)
Attachment #658628 - Flags: review?(chrislord.net)
Comment on attachment 658627 [details] [diff] [review] SingleTileLayer paint code caching (v2) Review of attachment 658627 [details] [diff] [review]: ----------------------------------------------------------------- kats, my comments here apply to both patches. ::: mobile/android/base/gfx/SingleTileLayer.java @@ +22,5 @@ > private static final String LOGTAG = "GeckoSingleTileLayer"; > > private Rect mMask; > > + // objects that we use often; keep these as class variables and reuse them The term "class variable" typically refers to Java static variables. I would say something like "instance variables". @@ +54,5 @@ > + mSubRect = new Rect(); > + mSubRectF = new RectF(); > + mMaskedBounds = new Region(); > + mCropRect = new Rect(); > + mCoords = new float[20]; You could initialize these variables when they are declared above (since their initialization doesn't rely on ctor parameters)? It's fewer lines of code. :)
(In reply to Chris Peterson (:cpeterson) from comment #12) > Comment on attachment 658627 [details] [diff] [review] > SingleTileLayer paint code caching (v2) > > Review of attachment 658627 [details] [diff] [review]: > ----------------------------------------------------------------- > > kats, my comments here apply to both patches. > > ::: mobile/android/base/gfx/SingleTileLayer.java > @@ +22,5 @@ > > private static final String LOGTAG = "GeckoSingleTileLayer"; > > > > private Rect mMask; > > > > + // objects that we use often; keep these as class variables and reuse them > > The term "class variable" typically refers to Java static variables. I would > say something like "instance variables". They're called "fields" in the Java API reference. If we're being pedantic, I'd rather we follow Java convention, make it easier for Java coders reading the source.
Comment on attachment 658627 [details] [diff] [review] SingleTileLayer paint code caching (v2) Review of attachment 658627 [details] [diff] [review]: ----------------------------------------------------------------- Looks fine to me. Nit-picks below. ::: mobile/android/base/gfx/SingleTileLayer.java @@ +22,5 @@ > private static final String LOGTAG = "GeckoSingleTileLayer"; > > private Rect mMask; > > + // objects that we use often; keep these as class variables and reuse them Not particularly keen on the wording here - how about "To avoid excessive GC, declare objects here that would otherwise be created and destroyed frequently during draw()"? @@ +54,5 @@ > + mSubRect = new Rect(); > + mSubRectF = new RectF(); > + mMaskedBounds = new Region(); > + mCropRect = new Rect(); > + mCoords = new float[20]; I have no strong feelings about the initialisation being done in the constructor. While it seems to have been our convention, it would look tidier if this was done above. Up to you.
Attachment #658627 - Flags: review?(chrislord.net) → review+
Comment on attachment 658628 [details] [diff] [review] ScrollbarLayer paint code caching Review of attachment 658628 [details] [diff] [review]: ----------------------------------------------------------------- Looks fine, though now that the setting of the buffers is stretched out, it makes it look even more silly that we don't have a utility function for that... ::: mobile/android/base/gfx/ScrollbarLayer.java @@ +37,5 @@ > private float mOpacity; > > + // objects that we use often; keep these as class variables and reuse them > + // rather than creating new transient ones every time. this should put less > + // stress on the GC Same comment as before, I'd be explicit about where these objects get used so it's more obvious that the GC in this case is a bad thing. @@ +135,5 @@ > + > + mBarRectF = new RectF(); > + mBarRect = new Rect(); > + mBodyCoords = new float[20]; > + mCap = new float[20]; Ditto here about tidiness/convention - your call. @@ +276,5 @@ > + mBodyCoords[15] = (mBarRect.left+mBarRect.width())/viewWidth; > + mBodyCoords[16] = (bot+mBarRect.height())/viewHeight; > + mBodyCoords[17] = 0; > + mBodyCoords[18] = BODY_TEX_COORDS[6]; > + mBodyCoords[19] = BODY_TEX_COORDS[7]; At some point, we should encapsulate 'draw a textured quad' into a utility function...
Attachment #658628 - Flags: review?(chrislord.net) → review+
You're right, filling in that float[20] is much better with some refactoring. It also removes a pile of redundant calculations (i.e. using rect.left + rect.width() instead of just using rect.right)
Attachment #658911 - Flags: review?(chrislord.net)
(In reply to Chris Lord [:cwiiis] from comment #14) > Not particularly keen on the wording here - how about "To avoid excessive > GC, declare objects here that would otherwise be created and destroyed > frequently during draw()"? I reworded the comment in both files to use this ^. > > @@ +54,5 @@ > > + mSubRect = new Rect(); > > + mSubRectF = new RectF(); > > + mMaskedBounds = new Region(); > > + mCropRect = new Rect(); > > + mCoords = new float[20]; > > I have no strong feelings about the initialisation being done in the > constructor. While it seems to have been our convention, it would look > tidier if this was done above. Up to you. Yeah I prefer putting all construction in the constructor, because otherwise the initialization code is split across different places and harder to find. I've left that as-is.
Comment on attachment 658911 [details] [diff] [review] Factor out a fillCoordBuffer function Review of attachment 658911 [details] [diff] [review]: ----------------------------------------------------------------- Much better :) ::: mobile/android/base/gfx/Layer.java @@ +153,5 @@ > mNewResolution = 0.0f; > } > } > > + protected final void fillCoordBuffer(float[] dest, RectF rect, float viewWidth, float viewHeight, I would like a better named function, or documentation here. Or both. Maybe just fillRectCoordBuffer?
Attachment #658911 - Flags: review?(chrislord.net) → review+
This issue is fixed on the latest Nightly build. Closing bug as verified fixed on: Firefox 18.0a1 (2012-09-12) Device: Galaxy Note OS: Android 4.0.4
Status: RESOLVED → VERIFIED
Blocks: 792154
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: