@@ -16,9 +16,9 @@ import { Barrier, timeout } from 'vs/base/common/async';
16
16
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService' ;
17
17
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite' ;
18
18
import { ViewContainerLocation } from 'vs/workbench/common/views' ;
19
- import { StopWatch } from 'vs/base/common/stopwatch' ;
20
19
import { TelemetryTrustedValue } from 'vs/platform/telemetry/common/telemetryUtils' ;
21
20
import { isWeb } from 'vs/base/common/platform' ;
21
+ import { createBlobWorker } from 'vs/base/browser/defaultWorkerFactory' ;
22
22
23
23
/* __GDPR__FRAGMENT__
24
24
"IMemoryInfo" : {
@@ -518,28 +518,42 @@ export abstract class AbstractTimerService implements ITimerService {
518
518
519
519
// we use fibonacci numbers to have a performance baseline that indicates
520
520
// how slow/fast THIS machine actually is.
521
- const sw = new StopWatch ( true ) ;
522
- let tooSlow = false ;
523
- function fib ( n : number ) : number {
524
- if ( tooSlow ) {
525
- return 0 ;
526
- }
527
- if ( sw . elapsed ( ) >= 1000 ) {
528
- tooSlow = true ;
529
- }
530
- if ( n <= 2 ) {
531
- return n ;
521
+
522
+ const jsSrc = ( function computeBaseline ( this : WindowOrWorkerGlobalScope ) {
523
+ // the following operation took ~16ms (one frame at 64FPS) to complete on my machine. We derive performance observations
524
+ // from that. We also bail if that took too long (>1s)
525
+ let tooSlow = false ;
526
+ function fib ( n : number ) : number {
527
+ if ( tooSlow ) {
528
+ return 0 ;
529
+ }
530
+ if ( performance . now ( ) - t1 >= 1000 ) {
531
+ tooSlow = true ;
532
+ }
533
+ if ( n <= 2 ) {
534
+ return n ;
535
+ }
536
+ return fib ( n - 1 ) + fib ( n - 2 ) ;
532
537
}
533
- return fib ( n - 1 ) + fib ( n - 2 ) ;
534
- }
535
538
536
- // the following operation took ~16ms (one frame at 64FPS) to complete on my machine. We derive performance observations
537
- // from that. We also bail if that took too long (>1s)
538
- sw . reset ( ) ;
539
- fib ( 24 ) ;
540
- const value = Math . round ( sw . elapsed ( ) ) ;
539
+ const t1 = performance . now ( ) ;
540
+ fib ( 24 ) ;
541
+ const value = Math . round ( performance . now ( ) - t1 ) ;
542
+ postMessage ( { value : tooSlow ? - 1 : value } ) ;
543
+
544
+ } ) . toString ( ) ;
545
+
546
+ const blob = new Blob ( [ `${ jsSrc } ;\ncomputeBaseline();` ] , { type : 'application/javascript' } ) ;
547
+ const blobUrl = URL . createObjectURL ( blob ) ;
548
+
549
+ const worker = createBlobWorker ( blobUrl , { name : 'perfBaseline' } ) ;
550
+ return new Promise < number > ( resolve => {
551
+ worker . onmessage = e => resolve ( e . data . value ) ;
541
552
542
- return ( tooSlow ? - 1 : value ) ;
553
+ } ) . finally ( ( ) => {
554
+ worker . terminate ( ) ;
555
+ URL . revokeObjectURL ( blobUrl ) ;
556
+ } ) ;
543
557
} ) ;
544
558
}
545
559
0 commit comments