@@ -39,6 +39,7 @@ export class TraceUtil {
3939 callstackType : EWrapperCallstackType = EWrapperCallstackType . FULL ;
4040 trace4Debug : string | null = null ;
4141 trace4Bypass : string | null = null ;
42+ #fullCallstackCacheTrace: Map < /*traceId*/ string , TTrace [ ] > = new Map ( ) ;
4243 static readonly SIGNATURE = 'browser-api-monitor' ;
4344
4445 constructor ( ) {
@@ -82,13 +83,22 @@ export class TraceUtil {
8283 }
8384
8485 #getFullCallstack( e : Error , uniqueTrait ?: unknown ) : TCallstack {
85- const trace = this . #getFullTrace( e . stack || '' ) ;
86- const traceId = e . stack || String ( uniqueTrait ) ;
86+ const traceId = hashString ( e . stack || String ( uniqueTrait ) ) ;
87+ const cached = this . #fullCallstackCacheTrace. get ( traceId ) ;
88+ let rv ;
8789
88- return {
89- traceId : hashString ( traceId ) ,
90- trace : trace || [ this . #getInvalidTrace( uniqueTrait ) ] ,
91- } ;
90+ if ( cached ) {
91+ rv = { traceId, trace : cached } ;
92+ } else {
93+ const trace = this . #getFullTrace( e . stack || '' ) ;
94+ rv = {
95+ traceId,
96+ trace : trace || [ this . #getInvalidTrace( uniqueTrait ) ] ,
97+ } ;
98+ this . #fullCallstackCacheTrace. set ( traceId , rv . trace ) ;
99+ }
100+
101+ return rv ;
92102 }
93103
94104 #getFullTrace( stackString : string ) : TTrace [ ] | null {
@@ -112,13 +122,13 @@ export class TraceUtil {
112122 let traceId ;
113123
114124 if ( trace ) {
115- traceId = trace . link ;
125+ traceId = hashString ( trace . link ) ;
116126 } else {
117- traceId = e . stack || String ( uniqueTrait ) ;
127+ traceId = hashString ( e . stack || String ( uniqueTrait ) ) ;
118128 trace = this . #getInvalidTrace( uniqueTrait ) ;
119129 }
120130
121- return { traceId : hashString ( traceId ) , trace : [ trace ] } ;
131+ return { traceId, trace : [ trace ] } ;
122132 }
123133
124134 #getShortTrace( stackString : string ) : TTrace | null {
0 commit comments