Skip to content

Commit

Permalink
For mozilla-mobile#21183: remove lazyMonitored wrapper functionality.
Browse files Browse the repository at this point in the history
We're not using the functionality so there's no sense in doing the work.
However, we keep the wrapper: see the code comments for details.
  • Loading branch information
mcomella authored and mergify[bot] committed Sep 8, 2021
1 parent 09fe569 commit 4fe6a45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 73 deletions.
44 changes: 7 additions & 37 deletions app/src/main/java/org/mozilla/fenix/perf/LazyMonitored.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,12 @@

package org.mozilla.fenix.perf

import mozilla.components.support.base.log.logger.Logger
import java.util.concurrent.atomic.AtomicInteger

private val logger = Logger("LazyMonitored")

/**
* A container for the number of components initialized.
*/
object ComponentInitCount {
val count = AtomicInteger(0)
}

/**
* A convenience function for setting the [LazyMonitored] property delegate, which wraps
* [lazy] to add performance monitoring.
* A function which wraps [lazy].
*
* This functionality was previously used to add performance monitoring. This
* wrapper could be useful in the future to add more monitoring. Even though
* this method is unused, we keep the code because re-adding this wrapper to
* every component is non-trivial.
*/
fun <T> lazyMonitored(initializer: () -> T): Lazy<T> = LazyMonitored(initializer)

/**
* A wrapper around the [lazy] property delegate to monitor for performance related issues.
* For example, we can count the number of components initialized to see how the number of
* components initialized on start up impacts start up time.
*/
private class LazyMonitored<T>(initializer: () -> T) : Lazy<T> {
// Lazy is thread safe.
private val lazyValue = lazy {
// We're unlikely to have 4 billion components so we don't handle overflow.
val componentInitCount = ComponentInitCount.count.incrementAndGet()

initializer().also {
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION") // the compiler fails with !! but warns with !!.
val className = if (it == null) "null" else it!!::class.java.canonicalName
logger.debug("Init component #$componentInitCount: $className")
}
}

override val value: T get() = lazyValue.value
override fun isInitialized(): Boolean = lazyValue.isInitialized()
}
fun <T> lazyMonitored(initializer: () -> T): Lazy<T> = lazy(initializer)
36 changes: 0 additions & 36 deletions app/src/test/java/org/mozilla/fenix/perf/LazyMonitoredTest.kt

This file was deleted.

0 comments on commit 4fe6a45

Please sign in to comment.