Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Add Renderer.renderCurrentBuffer() to tackle "First Frame Problem". #19

Merged
merged 2 commits into from
Jun 17, 2018

Conversation

artem-zinnatullin
Copy link
Contributor

Closes #14.

@artem-zinnatullin artem-zinnatullin added the enhancement New feature or request label Jun 11, 2018
@artem-zinnatullin artem-zinnatullin added this to the v0.1.0 milestone Jun 11, 2018
@artem-zinnatullin artem-zinnatullin self-assigned this Jun 11, 2018
/**
* "Renders" what is in the buffer at the moment, blocking the caller thread.
*
* Main purpose of this API is to add a way of solving ["First Frame Problem"](https://github.com/lyft/domic/issues/14).

Choose a reason for hiding this comment

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

Is markdown with links supported? Otherwise this might look weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renders fine in IntelliJ, afaik kotlindoc supports most of markdown

Choose a reason for hiding this comment

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

Dig. Didn't know.

import java.util.concurrent.TimeUnit.MILLISECONDS
import java.util.concurrent.atomic.AtomicInteger

class AndroidRenderer(
private val choreographer: Choreographer = Choreographer.getInstance(),
timeScheduler: Scheduler = Schedulers.computation(),
bufferTimeWindowMs: Long = 8, // We'll adjust if needed.
private val buffer: RenderingBuffer<Action> = RenderingBufferImpl()
private val buffer: RenderingBuffer<Action> = RenderingBufferImpl(),
private val renderingThreadChecker: Callable<Boolean> = Callable { Looper.myLooper() == Looper.getMainLooper() }

Choose a reason for hiding this comment

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

consider renaming this to mainThreadChecker, to avoid any confusion wrt RenderThread on android.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh, that was original name, but then I figured that it's too implementaiton
specific

but now I think it's fair for AndroidRenderer renderer to have such parameter name since it's AndroidRenderer and not just Renderer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed!

*/
@MainThread
override fun renderCurrentBuffer() {
if (renderingThreadChecker.call() == false) {

Choose a reason for hiding this comment

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

maybe you can just throw inside of the Callable? Would make the callsites cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's a bit harder to define an interface where no-op means ok and throws means expected error, also if we decide to use renderingThreadChecker.call() somewhere in the hot path and handle wrong thread case differently, exceptions will quickly become a performance bottleneck

Choose a reason for hiding this comment

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

All good points - especially performance in hot path 👍

@artem-zinnatullin artem-zinnatullin merged commit 71ebb58 into master Jun 17, 2018
@artem-zinnatullin artem-zinnatullin deleted the az/renderCurrentBuffer branch June 17, 2018 00:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants