@@ -54,6 +54,7 @@ import Framebuffer from '../gl/framebuffer';
5454import  { OcclusionParams }  from  './occlusion_params' ; 
5555import  { Rain }  from  '../precipitation/draw_rain' ; 
5656import  { Snow }  from  '../precipitation/draw_snow' ; 
57+ import  { PerformanceUtils }  from  '../util/performance' ; 
5758
5859import  type  ImageManager  from  './image_manager' ; 
5960import  type  IndexBuffer  from  '../gl/index_buffer' ; 
@@ -758,6 +759,8 @@ class Painter {
758759        this . _dt  =  curTime  -  this . _timeStamp ; 
759760        this . _timeStamp  =  curTime ; 
760761
762+         const  renderStartTime  =  PerformanceUtils . now ( ) ; 
763+ 
761764        Debug . run ( ( )  =>  {  this . updateAverageFPS ( ) ;  } ) ; 
762765
763766        // Update debug cache, i.e. clear all unused buffers 
@@ -816,17 +819,21 @@ class Painter {
816819        let  conflationSourcesInStyle  =  0 ; 
817820        let  conflationActiveThisFrame  =  false ; 
818821
822+         const  prepareStartTime  =  PerformanceUtils . now ( ) ; 
819823        for  ( const  id  in  sourceCaches )  { 
820824            const  sourceCache  =  sourceCaches [ id ] ; 
821825            if  ( sourceCache . used )  { 
826+                 const  sourceCachePrepareStartTime  =  PerformanceUtils . now ( ) ; 
822827                sourceCache . prepare ( this . context ) ; 
828+                 PerformanceUtils . measureLowOverhead ( `prepare: ${ sourceCache . id . toString ( ) }  ` ,  sourceCachePrepareStartTime ,  undefined ) ; 
823829
824830                // @ts -expect-error - TS2339 - Property 'usedInConflation' does not exist on type 'Source'. 
825831                if  ( sourceCache . getSource ( ) . usedInConflation )  { 
826832                    ++ conflationSourcesInStyle ; 
827833                } 
828834            } 
829835        } 
836+         PerformanceUtils . measureLowOverhead ( 'sourceCaches: prepare' ,  prepareStartTime ,  undefined ) ; 
830837
831838        let  clippingActiveThisFrame  =  false ; 
832839        for  ( const  layer  of  orderedLayers )  { 
@@ -1098,8 +1105,10 @@ class Painter {
10981105
10991106        // Shadow pass ================================================== 
11001107        if  ( this . _shadowRenderer )  { 
1108+             const  shadowPassStartTime  =  PerformanceUtils . now ( ) ; 
11011109            this . renderPass  =  'shadow' ; 
11021110            this . _shadowRenderer . drawShadowPass ( this . style ,  coordsShadowCasters ) ; 
1111+             PerformanceUtils . measureLowOverhead ( 'Shadow Pass' ,  shadowPassStartTime ) ; 
11031112        } 
11041113
11051114        // Rebind the main framebuffer now that all offscreen layers have been rendered: 
@@ -1145,7 +1154,7 @@ class Painter {
11451154        // Opaque pass =============================================== 
11461155        // Draw opaque layers top-to-bottom first. 
11471156        this . renderPass  =  'opaque' ; 
1148- 
1157+          const   opaquePassStartTime   =   PerformanceUtils . now ( ) ; 
11491158        if  ( this . style . fog  &&  this . transform . projection . supportsFog  &&  this . _atmosphere  &&  ! this . _showOverdrawInspector  &&  shouldRenderAtmosphere )  { 
11501159            this . _atmosphere . drawStars ( this ,  this . style . fog ) ; 
11511160        } 
@@ -1164,6 +1173,7 @@ class Painter {
11641173        if  ( this . style . fog  &&  this . transform . projection . supportsFog  &&  this . _atmosphere  &&  ! this . _showOverdrawInspector  &&  shouldRenderAtmosphere )  { 
11651174            this . _atmosphere . drawAtmosphereGlow ( this ,  this . style . fog ) ; 
11661175        } 
1176+         PerformanceUtils . measureLowOverhead ( 'Opaque Pass' ,  opaquePassStartTime ) ; 
11671177
11681178        // Sky pass ====================================================== 
11691179        // Draw all sky layers bottom to top. 
@@ -1185,7 +1195,7 @@ class Painter {
11851195        // Translucent pass =============================================== 
11861196        // Draw all other layers bottom-to-top. 
11871197        this . renderPass  =  'translucent' ; 
1188- 
1198+          const   translucentPassStartTime   =   PerformanceUtils . now ( ) ; 
11891199        function  coordsForTranslucentLayer ( layer : TypedStyleLayer ,  sourceCache ?: SourceCache )  { 
11901200            // For symbol layers in the translucent pass, we add extra tiles to the renderable set 
11911201            // for cross-tile symbol fading. Symbol layers don't use tile clipping, so no need to render 
@@ -1382,6 +1392,8 @@ class Painter {
13821392        if  ( this . _rain )  { 
13831393            this . _rain . draw ( this ) ; 
13841394        } 
1395+         PerformanceUtils . measureLowOverhead ( 'Translucent Pass' ,  translucentPassStartTime ) ; 
1396+ 
13851397        if  ( this . options . showTileBoundaries  ||  this . options . showQueryGeometry  ||  this . options . showTileAABBs )  { 
13861398            // Use source with highest maxzoom 
13871399            let  selectedSource  =  null ; 
@@ -1435,6 +1447,8 @@ class Painter {
14351447        if  ( ! conflationActiveThisFrame )  { 
14361448            this . conflationActive  =  false ; 
14371449        } 
1450+ 
1451+         PerformanceUtils . measureLowOverhead ( 'Painter.render' ,  renderStartTime ) ; 
14381452    } 
14391453
14401454    prepareLayer ( layer : TypedStyleLayer )  { 
@@ -1459,12 +1473,15 @@ class Painter {
14591473
14601474        this . id  =  layer . id ; 
14611475
1476+         const  startTime  =  PerformanceUtils . now ( ) ; 
14621477        this . gpuTimingStart ( layer ) ; 
14631478        if  ( ( ! painter . transform . projection . unsupportedLayers  ||  ! painter . transform . projection . unsupportedLayers . includes ( layer . type )  || 
14641479            ( painter . terrain  &&  layer . type  ===  'custom' ) )  &&  layer . type  !==  'clip' )  { 
14651480            draw [ layer . type ] ( painter ,  sourceCache ,  layer ,  coords ,  this . style . placement . variableOffsets ,  this . options . isInitialLoad ) ; 
14661481        } 
14671482        this . gpuTimingEnd ( ) ; 
1483+         // PerformanceUtils.measureLowOverhead(`${layer.type.toString()}:${layer.id.toString()}`, startTime, undefined); 
1484+         PerformanceUtils . measureLowOverhead ( `renderLayer: ${ layer . type . toString ( ) }  ` ,  startTime ,  undefined ) ; 
14681485    } 
14691486
14701487    gpuTimingStart ( layer : TypedStyleLayer )  { 
0 commit comments