Skip to content

Commit a3c47d3

Browse files
Xin Chenfacebook-github-bot
authored andcommitted
Replace RN Dev Tool perf logger usage of API 24 method in java.util.Comparator.naturalOrder
Summary: Previous diff D41486648 is causing crashes and a sev S311353, which is due to usages of an old Android API that only work after level 24 (D36500518 (0fc42fd)). ~~This diff updates the implementation to use a compatible API, but with worse runtime complexity.~~ ~~https://fburl.com/txd0r89e is a good explanation on the two algorithm to calculate a streaming median value. This diff uses the approach described in https://stackoverflow.com/a/4903642.~~ ## Update Following suggestion from sshic, I preserved the existing algorithm but with a custom comparator approach. Changelog: [Internal] Reviewed By: makovkastar Differential Revision: D41505143 fbshipit-source-id: 494e07fa627b5cf8bad7971fa5de86d270a7412c
1 parent 0f089ea commit a3c47d3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/fabric/DevToolsReactPerfLogger.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,27 @@
2121
import java.util.Queue;
2222

2323
class LongStreamingStats {
24-
private Queue<Long> minHeap = new PriorityQueue<>(Comparator.naturalOrder());
25-
private Queue<Long> maxHeap = new PriorityQueue<>(Comparator.reverseOrder());
24+
// TODO(T138627466): Calculate median value with better algorithm after Android API 24.
25+
private Queue<Long> minHeap =
26+
new PriorityQueue<>(
27+
11,
28+
new Comparator<Long>() {
29+
@Override
30+
public int compare(Long first, Long second) {
31+
// Natural order
32+
return Long.compare(first, second);
33+
}
34+
});
35+
private Queue<Long> maxHeap =
36+
new PriorityQueue<>(
37+
11,
38+
new Comparator<Long>() {
39+
@Override
40+
public int compare(Long first, Long second) {
41+
// Reversed order
42+
return Long.compare(second, first);
43+
}
44+
});
2645
private double streamingAverage = 0.0;
2746
private int len = 0;
2847
private long max = 0;

0 commit comments

Comments
 (0)