Skip to content

Commit

Permalink
Improve logging for resolving without size
Browse files Browse the repository at this point in the history
Summary: As per title

Reviewed By: adityasharat

Differential Revision: D66957544

fbshipit-source-id: 093bddffe29b823ba32e30cf3ed80fcf6c1631ce
  • Loading branch information
Andrew Wang authored and facebook-github-bot committed Dec 10, 2024
1 parent 9fe0eab commit 04a99a1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 deletions.
81 changes: 45 additions & 36 deletions litho-core/src/main/java/com/facebook/litho/ComponentTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -1975,49 +1975,55 @@ private void doResolve(
final @Nullable ResolveResult resolveResult = resolveResultHolder.result;

if (resolveResult == null) {
if (getLithoConfiguration().componentsConfig.enableResolveWithoutSizeSpec) {
final boolean isLoggingEnabled =
getLithoConfiguration().componentsConfig.enableLoggingForRenderInFlight;
final boolean enableResolveWithoutSizeSpec =
getLithoConfiguration().componentsConfig.enableResolveWithoutSizeSpec;
final boolean enableFixForResolveWithoutSizeSpec =
getLithoConfiguration().componentsConfig.enableFixForResolveWithoutSizeSpec;

if (isLoggingEnabled || enableResolveWithoutSizeSpec || enableFixForResolveWithoutSizeSpec) {
final boolean isWaitingButInterrupted =
(resolveResultHolder.type == TreeFuture.FutureExecutionType.REUSE_FUTURE)
&& (TreeFuture.FutureState.INTERRUPTED == resolveResultHolder.state);
TreeFuture.FutureState.WAITING == resolveResultHolder.state;
final boolean isLatestRequest;
synchronized (this) {
// To check if this is the latest resolve request and we don't want to get lost of it.
isLatestRequest = (localResolveVersion == (mNextResolveVersion - 1));
}
if (isWaitingButInterrupted && !ThreadUtils.isMainThread() && isLatestRequest) {
// If we found any interrupted async resolve task which is also the latest request, which
// means the current resolve request might be getting lost and we need to re-try it to
// make sure there's not render in flight.
requestRenderWithSplitFutures(
true,
output,
source,
extraAttribution,
widthSpec,
heightSpec,
root,
treePropContainer);
}

DebugInfoReporter.report(
"RenderInFlight:Null Result",
LogLevel.ERROR,
mId,
attributes -> {
attributes.put(DebugEventAttribute.Version, localResolveVersion);
attributes.put(DebugEventAttribute.Source, layoutSourceToString(source));
attributes.put("Root", root.getSimpleName());
attributes.put(DebugEventAttribute.Width, SizeSpec.toSimpleString(widthSpec));
attributes.put(DebugEventAttribute.Height, SizeSpec.toSimpleString(heightSpec));
attributes.put(
"withoutSizeSpec",
getLithoConfiguration().componentsConfig.enableResolveWithoutSizeSpec);
attributes.put("isLatestRequest", isLatestRequest);
attributes.put("isMainThread", ThreadUtils.isMainThread());
attributes.put("FutureExecutionType", resolveResultHolder.type);
attributes.put("FutureState", resolveResultHolder.state);
return Unit.INSTANCE;
});
if (isWaitingButInterrupted && isLatestRequest) {
if (enableFixForResolveWithoutSizeSpec) {
// If we found any interrupted async resolve task which is also the latest request,
// which
// means the current resolve request might be getting lost and we need to re-try it to
// make sure there's not render in flight.
requestRenderWithSplitFutures(
true,
output,
source,
extraAttribution,
widthSpec,
heightSpec,
root,
treePropContainer);
}
DebugInfoReporter.report(
"RenderInFlight v3:Null Result",
LogLevel.ERROR,
mId,
attributes -> {
attributes.put(DebugEventAttribute.Version, localResolveVersion);
attributes.put(DebugEventAttribute.Source, layoutSourceToString(source));
attributes.put("Root", root.getSimpleName());
attributes.put(DebugEventAttribute.Width, SizeSpec.toSimpleString(widthSpec));
attributes.put(DebugEventAttribute.Height, SizeSpec.toSimpleString(heightSpec));
attributes.put("withoutSizeSpec", enableResolveWithoutSizeSpec);
attributes.put("fix", enableFixForResolveWithoutSizeSpec);
attributes.put("FutureExecutionType", resolveResultHolder.type);
attributes.put("FutureState", resolveResultHolder.state);
return Unit.INSTANCE;
});
}
}
} else {
commitResolveResult(resolveResult);
Expand Down Expand Up @@ -2249,6 +2255,9 @@ public void doFrame(long frameTimeNanos) {
attributes.put(
"withoutSizeSpec",
getLithoConfiguration().componentsConfig.enableResolveWithoutSizeSpec);
attributes.put(
"fix",
getLithoConfiguration().componentsConfig.enableFixForResolveWithoutSizeSpec);
attributes.put(
"isRootNotCompatibleAndWithoutResolveFuture",
isRootNotCompatibleAndWithoutResolveFuture);
Expand Down
3 changes: 2 additions & 1 deletion litho-core/src/main/java/com/facebook/litho/TreeFuture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ abstract class TreeFuture<T : PotentiallyPartialResult>(
if (shouldWaitForResult && !isMainThread && !isFromSyncLayout(source)) {
return TreeFutureResult.interruptWithMessage(
type = type,
state = FutureState.INTERRUPTED,
state = FutureState.WAITING,
description = FUTURE_RESULT_NULL_REASON_SYNC_RESULT_NON_MAIN_THREAD)
}
if (isMainThread && shouldWaitForResult) {
Expand Down Expand Up @@ -456,6 +456,7 @@ abstract class TreeFuture<T : PotentiallyPartialResult>(

enum class FutureState {
SUCCESS,
WAITING,
INTERRUPTED,
RELEASED
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ internal constructor(
* possibility of reusing resolve result.
*/
@JvmField val enableResolveWithoutSizeSpec: Boolean = false,
/** This will enable the fix for render in flight */
@JvmField val enableFixForResolveWithoutSizeSpec: Boolean = false,
/** This will skip calling `onDraw` for ComponentHost. */
@JvmField val enableHostWillNotDraw: Boolean = false,
/** This will enable logging for render in-flight */
Expand Down Expand Up @@ -329,6 +331,7 @@ internal constructor(
private var enableResolveWithoutSizeSpec = baseConfig.enableResolveWithoutSizeSpec
private var enableHostWillNotDraw = baseConfig.enableHostWillNotDraw
private var enableLoggingForRenderInFlight = baseConfig.enableLoggingForRenderInFlight
private var enableFixForResolveWithoutSizeSpec = baseConfig.enableFixForResolveWithoutSizeSpec
private var enableFixForCachedNestedTree = baseConfig.enableFixForCachedNestedTree
private var isHostViewAttributesCleanUpEnabled = baseConfig.isHostViewAttributesCleanUpEnabled

Expand Down Expand Up @@ -430,6 +433,10 @@ internal constructor(
enableLoggingForRenderInFlight = enabled
}

fun enableFixForResolveWithoutSizeSpec(enabled: Boolean): Builder = also {
enableFixForResolveWithoutSizeSpec = enabled
}

fun enableFixForCachedNestedTree(enabled: Boolean): Builder = also {
enableFixForCachedNestedTree = enabled
}
Expand Down Expand Up @@ -472,6 +479,7 @@ internal constructor(
enableResolveWithoutSizeSpec = enableResolveWithoutSizeSpec,
enableHostWillNotDraw = enableHostWillNotDraw,
enableLoggingForRenderInFlight = enableLoggingForRenderInFlight,
enableFixForResolveWithoutSizeSpec = enableFixForResolveWithoutSizeSpec,
enableFixForCachedNestedTree = enableFixForCachedNestedTree,
isHostViewAttributesCleanUpEnabled = isHostViewAttributesCleanUpEnabled,
)
Expand Down

0 comments on commit 04a99a1

Please sign in to comment.