diff --git a/core/lib/dependency-graph/simulator/network-analyzer.js b/core/lib/dependency-graph/simulator/network-analyzer.js index d0c2f273f5d9..a1634187776d 100644 --- a/core/lib/dependency-graph/simulator/network-analyzer.js +++ b/core/lib/dependency-graph/simulator/network-analyzer.js @@ -139,14 +139,15 @@ class NetworkAnalyzer { return NetworkAnalyzer._estimateValueByOrigin(records, ({timing, connectionReused, record}) => { if (connectionReused) return; - if (timing.connectEnd > 0 && timing.connectStart > 0 && record.protocol.startsWith('h3')) { + const {connectStart, sslStart, sslEnd, connectEnd} = timing; + if (connectEnd >= 0 && connectStart >= 0 && record.protocol.startsWith('h3')) { // These values are equal to sslStart and sslEnd for h3. - return timing.connectEnd - timing.connectStart; - } else if (timing.sslStart > 0 && timing.sslEnd > 0) { + return connectEnd - connectStart; + } else if (sslStart >= 0 && sslEnd >= 0 && sslStart !== connectStart) { // SSL can also be more than 1 RT but assume False Start was used. - return [timing.connectEnd - timing.sslStart, timing.sslStart - timing.connectStart]; - } else if (timing.connectStart > 0 && timing.connectEnd > 0) { - return timing.connectEnd - timing.connectStart; + return [connectEnd - sslStart, sslStart - connectStart]; + } else if (connectStart >= 0 && connectEnd >= 0) { + return connectEnd - connectStart; } }); } diff --git a/core/test/fixtures/lantern-baseline-computed-values.json b/core/test/fixtures/lantern-baseline-computed-values.json index 447a9cf23794..e89cbc2a2f15 100644 --- a/core/test/fixtures/lantern-baseline-computed-values.json +++ b/core/test/fixtures/lantern-baseline-computed-values.json @@ -4,7 +4,7 @@ {"url": "http://www.zol.com.cn/", "roughEstimateOfFCP": 3296, "optimisticFCP": 3296, "pessimisticFCP": 3296, "roughEstimateOfFMP": 3296, "optimisticFMP": 3296, "pessimisticFMP": 3296, "roughEstimateOfTTI": 15560, "optimisticTTI": 14661, "pessimisticTTI": 16459, "roughEstimateOfSI": 12324, "optimisticSI": 4861, "pessimisticSI": 8876, "roughEstimateOfLCP": 4201, "optimisticLCP": 4123, "pessimisticLCP": 4279, "roughEstimateOfTTFB": 648}, {"url": "https://birdsarentreal.com", "roughEstimateOfFCP": 2950, "optimisticFCP": 2950, "pessimisticFCP": 2950, "roughEstimateOfFMP": 3434, "optimisticFMP": 3111, "pessimisticFMP": 3756, "roughEstimateOfTTI": 13409, "optimisticTTI": 12063, "pessimisticTTI": 14755, "roughEstimateOfSI": 5108, "optimisticSI": 1323, "pessimisticSI": 5393, "roughEstimateOfLCP": 7721, "optimisticLCP": 6959, "pessimisticLCP": 8483, "roughEstimateOfTTFB": 701}, {"url": "https://depositfiles.com/", "roughEstimateOfFCP": 5098, "optimisticFCP": 5098, "pessimisticFCP": 5098, "roughEstimateOfFMP": 5486, "optimisticFMP": 5098, "pessimisticFMP": 5874, "roughEstimateOfTTI": 5982, "optimisticTTI": 5854, "pessimisticTTI": 6109, "roughEstimateOfSI": 7568, "optimisticSI": 2787, "pessimisticSI": 6025, "roughEstimateOfLCP": 6034, "optimisticLCP": 6034, "pessimisticLCP": 6034, "roughEstimateOfTTFB": 907}, - {"url": "https://en-maktoob.yahoo.com/?p=xa", "roughEstimateOfFCP": 1350, "optimisticFCP": 1350, "pessimisticFCP": 1350, "roughEstimateOfFMP": 1366, "optimisticFMP": 1350, "pessimisticFMP": 1383, "roughEstimateOfTTI": 5816, "optimisticTTI": 5163, "pessimisticTTI": 6470, "roughEstimateOfSI": 3643, "optimisticSI": 1039, "pessimisticSI": 3751, "roughEstimateOfLCP": 6844, "optimisticLCP": 6703, "pessimisticLCP": 6984, "roughEstimateOfTTFB": 618}, + {"url": "https://en-maktoob.yahoo.com/?p=xa", "roughEstimateOfFCP": 1350, "optimisticFCP": 1350, "pessimisticFCP": 1350, "roughEstimateOfFMP": 1366, "optimisticFMP": 1350, "pessimisticFMP": 1383, "roughEstimateOfTTI": 5820, "optimisticTTI": 5166, "pessimisticTTI": 6474, "roughEstimateOfSI": 3644, "optimisticSI": 1039, "pessimisticSI": 3753, "roughEstimateOfLCP": 6848, "optimisticLCP": 6707, "pessimisticLCP": 6990, "roughEstimateOfTTFB": 618}, {"url": "https://en.softonic.com", "roughEstimateOfFCP": 2187, "optimisticFCP": 2187, "pessimisticFCP": 2187, "roughEstimateOfFMP": 2580, "optimisticFMP": 2187, "pessimisticFMP": 2973, "roughEstimateOfTTI": 31124, "optimisticTTI": 26796, "pessimisticTTI": 35453, "roughEstimateOfSI": 12951, "optimisticSI": 3067, "pessimisticSI": 13703, "roughEstimateOfLCP": 3907, "optimisticLCP": 3498, "pessimisticLCP": 4316, "roughEstimateOfTTFB": 899}, {"url": "https://gm.58.com/glsanfrancisco-sl/", "roughEstimateOfFCP": 3019, "optimisticFCP": 3019, "pessimisticFCP": 3019, "roughEstimateOfFMP": 3019, "optimisticFMP": 3019, "pessimisticFMP": 3019, "roughEstimateOfTTI": 4785, "optimisticTTI": 4436, "pessimisticTTI": 5134, "roughEstimateOfSI": 4605, "optimisticSI": 1762, "pessimisticSI": 3674, "roughEstimateOfLCP": 5337, "optimisticLCP": 5045, "pessimisticLCP": 5630, "roughEstimateOfTTFB": 787}, {"url": "https://m.facebook.com/", "roughEstimateOfFCP": 2438, "optimisticFCP": 2407, "pessimisticFCP": 2468, "roughEstimateOfFMP": 2438, "optimisticFMP": 2407, "pessimisticFMP": 2468, "roughEstimateOfTTI": 4822, "optimisticTTI": 4217, "pessimisticTTI": 5427, "roughEstimateOfSI": 2685, "optimisticSI": 479, "pessimisticSI": 3484, "roughEstimateOfLCP": 3422, "optimisticLCP": 3391, "pessimisticLCP": 3452, "roughEstimateOfTTFB": 626}, @@ -28,7 +28,7 @@ {"url": "https://www.att.com/", "roughEstimateOfFCP": 5590, "optimisticFCP": 5139, "pessimisticFCP": 6042, "roughEstimateOfFMP": 5750, "optimisticFMP": 5139, "pessimisticFMP": 6361, "roughEstimateOfTTI": 30035, "optimisticTTI": 27711, "pessimisticTTI": 32359, "roughEstimateOfSI": 9131, "optimisticSI": 1858, "pessimisticSI": 10430, "roughEstimateOfLCP": 13751, "optimisticLCP": 13671, "pessimisticLCP": 13831, "roughEstimateOfTTFB": 651}, {"url": "https://www.bing.com/", "roughEstimateOfFCP": 962, "optimisticFCP": 962, "pessimisticFCP": 962, "roughEstimateOfFMP": 1339, "optimisticFMP": 962, "pessimisticFMP": 1717, "roughEstimateOfTTI": 2491, "optimisticTTI": 2241, "pessimisticTTI": 2741, "roughEstimateOfSI": 1565, "optimisticSI": 467, "pessimisticSI": 1788, "roughEstimateOfLCP": 1548, "optimisticLCP": 1262, "pessimisticLCP": 1834, "roughEstimateOfTTFB": 608}, {"url": "https://www.blogger.com/about/", "roughEstimateOfFCP": 1528, "optimisticFCP": 1528, "pessimisticFCP": 1528, "roughEstimateOfFMP": 2103, "optimisticFMP": 1953, "pessimisticFMP": 2253, "roughEstimateOfTTI": 2245, "optimisticTTI": 2216, "pessimisticTTI": 2274, "roughEstimateOfSI": 6825, "optimisticSI": 4188, "pessimisticSI": 1865, "roughEstimateOfLCP": 2377, "optimisticLCP": 2274, "pessimisticLCP": 2480, "roughEstimateOfTTFB": 603}, - {"url": "https://www.cnet.com/", "roughEstimateOfFCP": 2575, "optimisticFCP": 2215, "pessimisticFCP": 2934, "roughEstimateOfFMP": 2811, "optimisticFMP": 2536, "pessimisticFMP": 3085, "roughEstimateOfTTI": 43130, "optimisticTTI": 39828, "pessimisticTTI": 46433, "roughEstimateOfSI": 15812, "optimisticSI": 1339, "pessimisticSI": 21828, "roughEstimateOfLCP": 4259, "optimisticLCP": 4179, "pessimisticLCP": 4339, "roughEstimateOfTTFB": 608}, + {"url": "https://www.cnet.com/", "roughEstimateOfFCP": 2575, "optimisticFCP": 2215, "pessimisticFCP": 2934, "roughEstimateOfFMP": 2811, "optimisticFMP": 2536, "pessimisticFMP": 3085, "roughEstimateOfTTI": 43130, "optimisticTTI": 39828, "pessimisticTTI": 46433, "roughEstimateOfSI": 15812, "optimisticSI": 1339, "pessimisticSI": 21827, "roughEstimateOfLCP": 4259, "optimisticLCP": 4179, "pessimisticLCP": 4339, "roughEstimateOfTTFB": 608}, {"url": "https://www.codewars.com", "roughEstimateOfFCP": 2239, "optimisticFCP": 2239, "pessimisticFCP": 2239, "roughEstimateOfFMP": 3431, "optimisticFMP": 2407, "pessimisticFMP": 4455, "roughEstimateOfTTI": 8773, "optimisticTTI": 7002, "pessimisticTTI": 10543, "roughEstimateOfSI": 3990, "optimisticSI": 834, "pessimisticSI": 4728, "roughEstimateOfLCP": 9584, "optimisticLCP": 9261, "pessimisticLCP": 9907, "roughEstimateOfTTFB": 609}, {"url": "https://www.dawn.com/", "roughEstimateOfFCP": 2573, "optimisticFCP": 2250, "pessimisticFCP": 2897, "roughEstimateOfFMP": 2816, "optimisticFMP": 2573, "pessimisticFMP": 3059, "roughEstimateOfTTI": 25689, "optimisticTTI": 23528, "pessimisticTTI": 27850, "roughEstimateOfSI": 10403, "optimisticSI": 1332, "pessimisticSI": 13519, "roughEstimateOfLCP": 3868, "optimisticLCP": 3221, "pessimisticLCP": 4516, "roughEstimateOfTTFB": 652}, {"url": "https://www.deviantart.com/", "roughEstimateOfFCP": 2920, "optimisticFCP": 2920, "pessimisticFCP": 2920, "roughEstimateOfFMP": 2920, "optimisticFMP": 2920, "pessimisticFMP": 2920, "roughEstimateOfTTI": 13172, "optimisticTTI": 11356, "pessimisticTTI": 14989, "roughEstimateOfSI": 3085, "optimisticSI": 996, "pessimisticSI": 2986, "roughEstimateOfLCP": 12002, "optimisticLCP": 10543, "pessimisticLCP": 13462, "roughEstimateOfTTFB": 1009}, diff --git a/core/test/lib/dependency-graph/simulator/network-analyzer-test.js b/core/test/lib/dependency-graph/simulator/network-analyzer-test.js index 2a74cca89387..de85462ad8e7 100644 --- a/core/test/lib/dependency-graph/simulator/network-analyzer-test.js +++ b/core/test/lib/dependency-graph/simulator/network-analyzer-test.js @@ -136,7 +136,15 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => { describe('#estimateRTTByOrigin', () => { it('should infer from tcp timing when available', () => { - const timing = {connectStart: 1, connectEnd: 100}; + const timing = {connectStart: 0, connectEnd: 99}; + const record = createRecord({networkRequestTime: 0, networkEndTime: 1, timing}); + const result = NetworkAnalyzer.estimateRTTByOrigin([record]); + const expected = {min: 99, max: 99, avg: 99, median: 99}; + assert.deepStrictEqual(result.get('https://example.com'), expected); + }); + + it('should infer only one estimate if tcp and ssl start times are equal', () => { + const timing = {connectStart: 0, connectEnd: 99, sslStart: 0, sslEnd: 99}; const record = createRecord({networkRequestTime: 0, networkEndTime: 1, timing}); const result = NetworkAnalyzer.estimateRTTByOrigin([record]); const expected = {min: 99, max: 99, avg: 99, median: 99}; @@ -144,7 +152,7 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => { }); it('should infer from tcp and ssl timing when available', () => { - const timing = {connectStart: 1, connectEnd: 100, sslStart: 50, sslEnd: 100}; + const timing = {connectStart: 0, connectEnd: 99, sslStart: 50, sslEnd: 99}; const record = createRecord({networkRequestTime: 0, networkEndTime: 1, timing}); const result = NetworkAnalyzer.estimateRTTByOrigin([record]); const expected = {min: 49, max: 50, avg: 49.5, median: 49.5}; @@ -152,7 +160,7 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => { }); it('should infer from connection timing when available for h3 (one estimate)', () => { - const timing = {connectStart: 1, connectEnd: 100, sslStart: 1, sslEnd: 100}; + const timing = {connectStart: 0, connectEnd: 99, sslStart: 1, sslEnd: 99}; const record = createRecord({networkRequestTime: 0, networkEndTime: 1, timing, protocol: 'h3'}); const result = NetworkAnalyzer.estimateRTTByOrigin([record]);