Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize text_classifer model memory usage #21960

Closed
atuchin-m opened this issue Mar 29, 2022 · 8 comments
Closed

Optimize text_classifer model memory usage #21960

atuchin-m opened this issue Mar 29, 2022 · 8 comments

Comments

@atuchin-m
Copy link
Contributor

Related issue: #21602
Parsed text classifier model (component id : emgmepnebbddgnkhfmhdhmjifkglkamo) takes ~24mb of memory in Ads Service process.

It's looks excessive and we should find a way to make it smaller.
Another problem is that peak usage on start is more than 200mb.

Here is the code that produce 24mb memory allocation: https://github.com/brave/brave-core/blob/master/vendor/bat-native-ads/src/bat/ads/internal/ml/pipeline/text_processing/text_processing.cc#L63

@atuchin-m atuchin-m added OS/Android Fixes related to Android browser functionality OS/Desktop labels Mar 29, 2022
@atuchin-m atuchin-m self-assigned this Mar 29, 2022
@atuchin-m atuchin-m added the perf label Mar 29, 2022
@atuchin-m atuchin-m added this to the 1.39.x - Nightly milestone Mar 30, 2022
@atuchin-m atuchin-m added the OS/iOS Fixes related to iOS browser functionality label Apr 5, 2022
@atuchin-m
Copy link
Contributor Author

For QA:

  1. check that ads text classification works well.
  2. check memory consumption of ads service browser (for non-ios) or main process (for ios) is reduced.

@btlechowski
Copy link

Verification passed on

Brave 1.39.87 Chromium: 101.0.4951.41 (Official Build) beta (64-bit)
Revision 93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951@{#904}
OS Ubuntu 18.04 LTS

Reproduced the issue in 1.38.x

Verify that the issuers were downloaded

[18839:18839:0509/225506.081261:VERBOSE1:issuers.cc(80)] OnGetIssuers
[18839:18839:0509/225506.081836:VERBOSE6:issuers.cc(82)] URL Response:
  URL: https://ads-serve.brave.com/v1/issuers/
  Response Status Code: 200

Verify that unblinded tokens are downloaded


[18839:18839:0509/225526.441519:VERBOSE1:refill_unblinded_tokens.cc(323)] Added 50 unblinded tokens, you now have 50 unblinded tokens
[18839:18839:0509/225526.441569:VERBOSE1:account.cc(292)] Successfully refilled unblinded tokens


Verified ad related components are downloaded in brave://components

NTP Sponsored Images (US) - Version: 1.0.803
Brave Ads Resources (US) - Version: 1.0.47
Brave Ads Resources (en) - Version: 1.0.41

image

Viewed an ad and dimissed it

The memory used is 37352KB

image

Verified fixed in 1.39.x

Verify that the issuers were downloaded


[19550:19550:0510/001142.312340:VERBOSE1:issuers.cc(80)] OnGetIssuers
[19550:19550:0510/001142.312388:VERBOSE6:issuers.cc(82)] URL Response:
  URL: https://static.ads.brave.com/v1/issuers/
  Response Status Code: 200


Verify that unblinded tokens are downloaded


[19550:19550:0510/001153.082434:VERBOSE1:refill_unblinded_tokens.cc(322)] Added 50 unblinded tokens, you now have 50 unblinded tokens
[19550:19550:0510/001153.082709:VERBOSE1:account.cc(291)] Successfully refilled unblinded tokens


Verified ad related components are downloaded in brave://components

NTP Sponsored Images (US) - Version: 1.0.803
Brave Ads Resources (US) - Version: 1.0.47
Brave Ads Resources (en) - Version: 1.0.41

image

Viewed an ad and dimissed it

The memory used is 19252KB, which is less than in 1.38.x

image

@LaurenWags
Copy link
Member

LaurenWags commented May 10, 2022

Verified with

Brave | 1.39.96 Chromium: 101.0.4951.54 (Official Build) beta (x86_64)
-- | --
Revision | 67da1aeb32cedd27634ca6634fb79cbd85d3f0ab-refs/branch-heads/4951@{#1126}
OS | macOS Version 12.3.1 (Build 21E258)
Upgrade case - PASSED

Reproduced the issue in 1.38.x

Verify that the issuers were downloaded

[63005:259:0510/104743.175558:VERBOSE1:issuers.cc(80)] OnGetIssuers
[63005:259:0510/104743.175613:VERBOSE6:issuers.cc(82)] URL Response:
  URL: https://ads-serve.brave.com/v1/issuers/
  Response Status Code: 200

Verify that unblinded tokens are downloaded

[63005:259:0510/104747.967900:VERBOSE1:refill_unblinded_tokens.cc(323)] Added 50 unblinded tokens, you now have 50 unblinded tokens

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (US) - Version: 1.0.803
Brave Ads Resources (US) - Version: 1.0.47
Brave Ads Resources (en) - Version: 1.0.41

components

Viewed an ad and dismissed it

The memory used is 40.2 MB

1 38

Upgraded to 1.39.x.

Viewed another ad and dismissed it

The memory used is now 20.6 MB which is less than 1.38.x.

upgrade
Clean profile - PASSED

Verified fixed in 1.39.x

Verify that the issuers were downloaded

[63700:259:0510/111121.755709:VERBOSE1:issuers.cc(80)] OnGetIssuers
[63700:259:0510/111121.755747:VERBOSE6:issuers.cc(82)] URL Response:
  URL: https://static.ads.brave.com/v1/issuers/
  Response Status Code: 200

Verify that unblinded tokens are downloaded

[63700:259:0510/111126.202639:VERBOSE1:refill_unblinded_tokens.cc(322)] Added 50 unblinded tokens, you now have 50 unblinded tokens

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (US) - Version: 1.0.803
Brave Ads Resources (US) - Version: 1.0.47
Brave Ads Resources (en) - Version: 1.0.41

components

Viewed an ad and dismissed it

The memory used is 22.6 MB, which is less than in 1.38.x

1 39

@MadhaviSeelam
Copy link

MadhaviSeelam commented May 12, 2022

Verified PASSED using

Brave | 1.39.101 Chromium: 101.0.4951.64 (Official Build) beta (64-bit)
-- | --
Revision | d1daa9897e1bc1d507d6be8f2346e377e5505905-refs/branch-heads/4951@{#1208}
OS | Windows 11 Version 21H2 (Build 22000.613)

Upgrade case - PASSED

Reproduced the issue in 1.38.x

Verify that the issuers were downloaded

[23196:9540:0512/110429.224:VERBOSE1:ad_server.cc(156)] Fetch catalog in 0 hours, 54 minutes, 46 seconds at 11:59:15.221[23196:9540:0512/110429.225:VERBOSE1:issuers.cc(80)] OnGetIssuers
[23196:9540:0512/110429.225:VERBOSE6:issuers.cc(82)] URL Response:
  URL: https://static.ads.brave.com/v1/issuers/
  Response Status Code: 200

Verify that unblinded tokens are downloaded

[9092:5784:0512/152309.413:VERBOSE1:refill_unblinded_tokens.cc(323)] Added 50 unblinded tokens, you now have 50 unblinded tokens

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (US) - Version: 1.0.805
Brave Ads Resources (US) - Version: 1.0.47
Brave Ads Resources (en) - Version: 1.0.41

components

Viewed an ad and dismissed it

####The memory used is 32,876K

taskmanager1

Upgraded to 1.39.x

Viewed another ad and dismissed it

The memory used is now 14,748K which is less than 1.38.x

taskmanager2
Clean profile - PASSED

Verified fixed in 1.39.x

Verify that the issuers were downloaded

[17192:15544:0512/153710.322:VERBOSE1:issuers.cc(80)] OnGetIssuers
[17192:15544:0512/153710.322:VERBOSE6:issuers.cc(82)] URL Response:
  URL: https://static.ads.brave.com/v1/issuers/
  Response Status Code: 200

Verify that unblinded tokens are downloaded

``` [10668:8624:0512/164555.140:VERBOSE1:refill_unblinded_tokens.cc(322)] Added 50 unblinded tokens, you now have 50 unblinded tokens ```

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (US) - Version: 1.0.805
Brave Ads Resources (US) - Version: 1.0.47
Brave Ads Resources (en) - Version: 1.0.41

components2

Viewed an ad and dismissed it

The memory used is 14,876K, which is less than in 1.38.x

taskmanager3

@atuchin-m
Copy link
Contributor Author

@LaurenWags @LaurenWags @btlechowski Big thanks for verification!

Just want to clarify one thing: Memory footprint on Linux/Mac is counted in a different way that on Windows.
That's why it's ok that absolute numbers are not match across OSes, so please don't be confused by this.

@LaurenWags
Copy link
Member

Makes sense, thanks for the clarification @atuchin-m 👍🏻

@kjozwiak
Copy link
Member

kjozwiak commented May 23, 2022

Verification PASSED on Samsung S10+ running Android 12 using the following build(s):

Brave | 1.39.111 Chromium: 102.0.5005.61 (Official Build) (64-bit)
--- | ---
Revision | 0e59bcc00cc4985ce39ad31c150065f159d95ad3-refs/branch-heads/5005@{#819}
OS | Android 12; Build/SP1A.210812.016

Reproduced the issue in 1.38.x

Verify that the issuers were downloaded

2022-05-23 12:04:28.931 31131-31131/? V/chromium: [VERBOSE1:issuers.cc(80)] OnGetIssuers
2022-05-23 12:04:28.931 31131-31131/? V/chromium: [VERBOSE6:issuers.cc(82)] URL Response:
URL: https://ads-serve.brave.com/v1/issuers/
Response Status Code: 200

Verify that unblinded tokens are downloaded

2022-05-23 12:04:43.008 31131-31131/? V/chromium: [VERBOSE1:refill_unblinded_tokens.cc(323)] Added 50 unblinded tokens, you now have 50 unblinded tokens
2022-05-23 12:04:43.009 31131-31131/? V/chromium: [VERBOSE1:account.cc(292)] Successfully refilled unblinded tokens

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (CA) - Version: 1.0.149
Brave Ads Resources (CA) - Version: 1.0.49
Brave Ads Resources (en) - Version: 1.0.41

Screenshot_20220523-124501_Brave

Viewed an ad and dismissed it

The memory used is 39.9 MiB

broken

Verified fixed in 1.39.x via Clean Install

Verify that the issuers were downloaded

2022-05-23 12:35:06.549 12198-12198/? V/chromium: [VERBOSE1:issuers.cc(80)] OnGetIssuers
2022-05-23 12:35:06.549 12198-12198/? V/chromium: [VERBOSE6:issuers.cc(82)] URL Response:
URL: https://ads-serve.brave.com/v1/issuers/
Response Status Code: 200

Verify that unblinded tokens are downloaded

2022-05-23 13:08:52.085 23957-23957/? V/chromium: [VERBOSE1:refill_unblinded_tokens.cc(322)] Added 50 unblinded tokens, you now have 50 unblinded tokens
2022-05-23 13:08:52.085 23957-23957/? V/chromium: [VERBOSE1:account.cc(291)] Successfully refilled unblinded tokens

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (CA) - Version: 1.0.149
Brave Ads Resources (CA) - Version: 1.0.49
Brave Ads Resources (en) - Version: 1.0.41

Screenshot_20220523-132254_Brave

Viewed an ad and dimissed it

The memory used is 22.3 MiB, which is less than in 1.38.x

image

Verified fixed in 1.39.x via Upgrade

Verify that the issuers were downloaded using 1.38.x

2022-05-23 13:32:47.465 6796-6796/? V/chromium: [VERBOSE6:issuers.cc(82)] URL Response:
URL: https://ads-serve.brave.com/v1/issuers/
Response Status Code: 200

Verify that unblinded tokens are downloaded using 1.38.x

2022-05-23 13:32:58.510 6796-6796/? V/chromium: [VERBOSE1:refill_unblinded_tokens.cc(323)] Added 50 unblinded tokens, you now have 50 unblinded tokens
2022-05-23 13:32:58.511 6796-6796/? V/chromium: [VERBOSE1:account.cc(292)] Successfully refilled unblinded tokens

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (CA) - Version: 1.0.149
Brave Ads Resources (CA) - Version: 1.0.49
Brave Ads Resources (en) - Version: 1.0.41

Screenshot_20220523-124501_Brave

Viewed an ad and dismissed using 1.38.x

The memory used is 40.3 MiB, which is less than in 1.38.x

image

Upgraded to 1.39.x and viewed/dismissed and ad as per the following:

The memory used is 22.6 MiB, which is less than in 1.38.x

image

@kjozwiak
Copy link
Member

Verification PASSED on Samsung Galaxy Tablet A running Android 11 using the following build(s):

Brave | 1.39.111 Chromium: 102.0.5005.61 (Official Build) (64-bit)
--- | ---
Revision | 0e59bcc00cc4985ce39ad31c150065f159d95ad3-refs/branch-heads/5005@{#819}
OS | Android 11; Build/RP1A.200720.012

Reproduced the issue in 1.38.x

Verify that the issuers were downloaded

2022-05-23 14:06:17.345 9005-9005/? V/chromium: [VERBOSE1:issuers.cc(80)] OnGetIssuers
2022-05-23 14:06:17.346 9005-9005/? V/chromium: [VERBOSE6:issuers.cc(82)] URL Response:
URL: https://ads-serve.brave.com/v1/issuers/
Response Status Code: 200

Verify that unblinded tokens are downloaded

2022-05-23 14:29:26.897 18263-18263/? V/chromium: [VERBOSE1:refill_unblinded_tokens.cc(323)] Added 50 unblinded tokens, you now have 50 unblinded tokens
2022-05-23 14:29:26.897 18263-18263/? V/chromium: [VERBOSE1:account.cc(292)] Successfully refilled unblinded tokens

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (CA) - Version: 1.0.149
Brave Ads Resources (CA) - Version: 1.0.49
Brave Ads Resources (en) - Version: 1.0.41

Screenshot_20220523-141216_Brave

Viewed an ad and dismissed it

The memory used is 33.1 MiB

image

Verified fixed in 1.39.x via Clean Install

Verify that the issuers were downloaded

2022-05-23 14:38:39.641 24767-24767/? V/chromium: [VERBOSE1:issuers.cc(80)] OnGetIssuers
2022-05-23 14:38:39.641 24767-24767/? V/chromium: [VERBOSE6:issuers.cc(82)] URL Response:
URL: https://static.ads.brave.com/v1/issuers/
Response Status Code: 200

Verify that unblinded tokens are downloaded

2022-05-23 14:38:45.407 24767-24767/? V/chromium: [VERBOSE1:refill_unblinded_tokens.cc(322)] Added 50 unblinded tokens, you now have 50 unblinded tokens
2022-05-23 14:38:45.407 24767-24767/? V/chromium: [VERBOSE1:account.cc(291)] Successfully refilled unblinded tokens

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (CA) - Version: 1.0.149
Brave Ads Resources (CA) - Version: 1.0.49
Brave Ads Resources (en) - Version: 1.0.41

Screenshot_20220523-144019_Brave

Viewed an ad and dimissed it

The memory used is 6.8 MiB, which is less than in 1.38.x

image

Verified fixed in 1.39.x via Upgrade

Verify that the issuers were downloaded using 1.38.x

2022-05-23 14:06:17.345 9005-9005/? V/chromium: [VERBOSE1:issuers.cc(80)] OnGetIssuers
2022-05-23 14:06:17.346 9005-9005/? V/chromium: [VERBOSE6:issuers.cc(82)] URL Response:
URL: https://ads-serve.brave.com/v1/issuers/
Response Status Code: 200

Verify that unblinded tokens are downloaded using 1.38.x

2022-05-23 14:29:26.897 18263-18263/? V/chromium: [VERBOSE1:refill_unblinded_tokens.cc(323)] Added 50 unblinded tokens, you now have 50 unblinded tokens
2022-05-23 14:29:26.897 18263-18263/? V/chromium: [VERBOSE1:account.cc(292)] Successfully refilled unblinded tokens

Verified ad related components are downloaded in brave://components

NTP Sponsored Images (CA) - Version: 1.0.149
Brave Ads Resources (CA) - Version: 1.0.49
Brave Ads Resources (en) - Version: 1.0.41

Screenshot_20220523-141216_Brave

Viewed an ad and dismissed using 1.38.x

The memory used is 40.3 MiB, which is less than in 1.38.x

image

Upgraded to 1.39.x and viewed/dismissed and ad as per the following:

The memory used is 12.9 MiB, which is less than in 1.38.x

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants