Skip to content

REPLAY-1727: Base64 Caching Mechanism#1534

Merged
jonathanmos merged 2 commits into
feature/base64-jmoskovichfrom
jmoskovich/replay-1727/base64-caching
Jul 19, 2023
Merged

REPLAY-1727: Base64 Caching Mechanism#1534
jonathanmos merged 2 commits into
feature/base64-jmoskovichfrom
jmoskovich/replay-1727/base64-caching

Conversation

@jonathanmos

@jonathanmos jonathanmos commented Jul 10, 2023

Copy link
Copy Markdown
Member

What does this PR do?

Adds an LRUCache for base64 strings - cache base64 strings against drawable hashcodes.
Evict all items in the LRUCache every time we change views.

Motivation

Without a caching mechanism we create and garbage collect an excessive number of bitmaps.

Additional Notes

This PR contains a revert commit of the revert of imagebuttonmapper (iow it adds base64 functionality back)

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@codecov-commenter

codecov-commenter commented Jul 10, 2023

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 78.31325% with 18 lines in your changes missing coverage. Please review.

Project coverage is 83.32%. Comparing base (ee5007f) to head (9d3d7a8).

Current head 9d3d7a8 differs from pull request most recent head 257722b

Please upload reports for the commit 257722b to get more accurate results.

Files with missing lines Patch % Lines
...nreplay/internal/recorder/base64/Base64LRUCache.kt 71.43% 12 Missing ⚠️
...eplay/internal/recorder/base64/Base64Serializer.kt 82.76% 4 Missing and 1 partial ⚠️
...play/internal/recorder/mapper/ImageButtonMapper.kt 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##           feature/base64-jmoskovich    #1534      +/-   ##
=============================================================
- Coverage                      83.66%   83.32%   -0.34%     
=============================================================
  Files                            438      439       +1     
  Lines                          14854    14927      +73     
  Branches                        2237     2250      +13     
=============================================================
+ Hits                           12427    12437      +10     
- Misses                          1868     1897      +29     
- Partials                         559      593      +34     
Files with missing lines Coverage Δ
...adog/android/sessionreplay/SessionReplayPrivacy.kt 100.00% <100.00%> (ø)
...nreplay/internal/async/RecordedDataQueueHandler.kt 89.39% <100.00%> (+0.87%) ⬆️
...ay/internal/recorder/mapper/BaseWireframeMapper.kt 78.57% <100.00%> (+0.79%) ⬆️
...play/internal/recorder/mapper/ImageButtonMapper.kt 91.43% <75.00%> (+7.05%) ⬆️
...eplay/internal/recorder/base64/Base64Serializer.kt 88.41% <82.76%> (-1.39%) ⬇️
...nreplay/internal/recorder/base64/Base64LRUCache.kt 71.43% <71.43%> (ø)

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jonathanmos
jonathanmos force-pushed the jmoskovich/replay-1727/base64-caching branch from 8418b54 to 7754a16 Compare July 10, 2023 11:33
@jonathanmos
jonathanmos force-pushed the jmoskovich/replay-1727/base64-caching branch from 7754a16 to 5e57c0b Compare July 10, 2023 11:36
@jonathanmos
jonathanmos force-pushed the jmoskovich/replay-1727/base64-caching branch from 5e57c0b to 3c431ae Compare July 10, 2023 11:54
@jonathanmos
jonathanmos force-pushed the jmoskovich/replay-1727/base64-caching branch from 3c431ae to 92ba7a7 Compare July 10, 2023 12:42
@jonathanmos
jonathanmos marked this pull request as ready for review July 10, 2023 13:00
@jonathanmos
jonathanmos requested a review from a team as a code owner July 10, 2023 13:00

@mariusc83 mariusc83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to test and register that callback

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice idea! I've added some comments to discuss.

}

@VisibleForTesting
internal fun setBackingCache(cache: LruCache<Int, String>) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: maybe just a provider (Int) -> LruCache in the constructor with default value for prod and mock value for tests?

@jonathanmos
jonathanmos force-pushed the jmoskovich/replay-1727/base64-caching branch from 57d6d54 to af3259a Compare July 11, 2023 14:11
@jonathanmos
jonathanmos changed the base branch from develop to feature/base64-jmoskovich July 11, 2023 14:12
@jonathanmos
jonathanmos force-pushed the jmoskovich/replay-1727/base64-caching branch from a9c7810 to 69e1ffe Compare July 17, 2023 11:15
@xgouchet
xgouchet self-requested a review July 17, 2023 11:25
@jonathanmos
jonathanmos force-pushed the jmoskovich/replay-1727/base64-caching branch from 69e1ffe to 3e9b47a Compare July 17, 2023 11:33
@jonathanmos
jonathanmos requested review from 0xnm and mariusc83 July 17, 2023 11:54
private const val ON_MODERATE_MEMORY_SIZE_BYTES = (MAX_CACHE_MEMORY_SIZE_BYTES / 4) * 3 // 75% size
private var componentCallbacksRegistered = false

private var cache: LruCache<String, ByteArray> = object :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: for testing we can remove this mutability and inject a provider, but I'm not pushing for it (just it is better to have less mutability).

@mariusc83 mariusc83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now. Nicely done.

@jonathanmos
jonathanmos requested a review from 0xnm July 18, 2023 13:31

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some questions and suggestions, but overall I think it is good to go.

}

private fun getPrefixForDrawableContainer(drawable: DrawableContainer): String {
if (drawable !is AnimationDrawable) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means that the key for the AnimationDrawable will always be the same independent of the state? meaning that even state of AnimationDrawable has changed then the cache entry for the first known state will be served? Is it is an intention we want to have?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, its just a fix to avoid having AnimationDrawable take up too much space in the lrucache. We'll need to have a discussion/brainstorming if we decide we want to send animations with base64, and this will in any case cease to be an issue once we have the resources endpoint.

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment about internalLogger storage, it is a potential memory leak.

@jonathanmos
jonathanmos force-pushed the jmoskovich/replay-1727/base64-caching branch 4 times, most recently from 1f11ad4 to 9d3d7a8 Compare July 19, 2023 10:21
@jonathanmos
jonathanmos requested a review from 0xnm July 19, 2023 11:26
@jonathanmos
jonathanmos force-pushed the jmoskovich/replay-1727/base64-caching branch from 9d3d7a8 to 257722b Compare July 19, 2023 11:45
@jonathanmos
jonathanmos merged commit f8cc3e6 into feature/base64-jmoskovich Jul 19, 2023
@jonathanmos
jonathanmos deleted the jmoskovich/replay-1727/base64-caching branch July 19, 2023 12:04
@xgouchet xgouchet added this to the 2.2.0 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants