@@ -112,10 +112,6 @@ export class WebSocketDriftClientAccountSubscriberV2
112
112
113
113
public async subscribe ( ) : Promise < boolean > {
114
114
const startTime = performance . now ( ) ;
115
- console . log (
116
- `[PROFILING] WebSocketDriftClientAccountSubscriberV2.subscribe() started at ${ new Date ( ) . toISOString ( ) } `
117
- ) ;
118
-
119
115
if ( this . isSubscribed ) {
120
116
console . log (
121
117
`[PROFILING] WebSocketDriftClientAccountSubscriberV2.subscribe() skipped - already subscribed`
@@ -154,13 +150,6 @@ export class WebSocketDriftClientAccountSubscriberV2
154
150
] ) ;
155
151
const pubkeyEndTime = performance . now ( ) ;
156
152
const pubkeyDuration = pubkeyEndTime - pubkeyStartTime ;
157
- console . log (
158
- `[PROFILING] Public key generation completed in ${ pubkeyDuration . toFixed (
159
- 2
160
- ) } ms (${ perpMarketAccountPubkeys . length } perp markets, ${
161
- spotMarketAccountPubkeys . length
162
- } spot markets)`
163
- ) ;
164
153
165
154
// Profile findAllMarketsAndOracles if needed
166
155
let findAllMarketsDuration = 0 ;
@@ -197,23 +186,6 @@ export class WebSocketDriftClientAccountSubscriberV2
197
186
`[PROFILING] findAllMarketAndOracles skipped (shouldFindAllMarketsAndOracles=false)`
198
187
) ;
199
188
}
200
-
201
- // Profile state public key generation
202
- const statePubkeyStartTime = performance . now ( ) ;
203
- const statePublicKey = await getDriftStateAccountPublicKey (
204
- this . program . programId
205
- ) ;
206
- const statePubkeyEndTime = performance . now ( ) ;
207
- const statePubkeyDuration = statePubkeyEndTime - statePubkeyStartTime ;
208
- console . log (
209
- `[PROFILING] State public key generation completed in ${ statePubkeyDuration . toFixed (
210
- 2
211
- ) } ms`
212
- ) ;
213
-
214
- // Profile parallel market and state subscriptions
215
- const parallelSubStartTime = performance . now ( ) ;
216
-
217
189
// Create subscribers
218
190
this . perpMarketAllAccountsSubscriber =
219
191
new WebSocketProgramAccountSubscriberV2 < PerpMarketAccount > (
@@ -247,15 +219,6 @@ export class WebSocketDriftClientAccountSubscriberV2
247
219
spotMarketAccountPubkeys // because we pass these in, it will monitor these accounts and fetch them right away
248
220
) ;
249
221
250
- this . stateAccountSubscriber = new WebSocketAccountSubscriberV2 (
251
- 'state' ,
252
- this . program ,
253
- statePublicKey ,
254
- undefined ,
255
- undefined ,
256
- this . commitment as Commitment
257
- ) ;
258
-
259
222
// Run all subscriptions in parallel
260
223
await Promise . all ( [
261
224
// Perp market subscription
@@ -303,43 +266,40 @@ export class WebSocketDriftClientAccountSubscriberV2
303
266
}
304
267
) ,
305
268
// State account subscription
306
- this . stateAccountSubscriber . subscribe ( ( data : StateAccount ) => {
307
- this . eventEmitter . emit ( 'stateAccountUpdate' , data ) ;
308
- this . eventEmitter . emit ( 'update' ) ;
309
- } ) ,
269
+ ( async ( ) => {
270
+ const statePublicKey = await getDriftStateAccountPublicKey (
271
+ this . program . programId
272
+ ) ;
273
+ this . stateAccountSubscriber = new WebSocketAccountSubscriberV2 (
274
+ 'state' ,
275
+ this . program ,
276
+ statePublicKey ,
277
+ undefined ,
278
+ undefined ,
279
+ this . commitment as Commitment
280
+ ) ;
281
+ this . stateAccountSubscriber . subscribe ( ( data : StateAccount ) => {
282
+ this . eventEmitter . emit ( 'stateAccountUpdate' , data ) ;
283
+ this . eventEmitter . emit ( 'update' ) ;
284
+ } ) ;
285
+ } ) ( ) ,
310
286
( async ( ) => {
311
287
await this . setInitialData ( ) ;
312
288
const subscribeToOraclesStartTime = performance . now ( ) ;
313
289
await this . subscribeToOracles ( ) ;
314
290
const subscribeToOraclesEndTime = performance . now ( ) ;
315
291
const duration =
316
292
subscribeToOraclesEndTime - subscribeToOraclesStartTime ;
317
- console . log (
318
- `[PROFILING] subscribeToOracles completed in ${ duration . toFixed ( 2 ) } ms`
319
- ) ;
320
293
return duration ;
321
294
} ) ( ) ,
322
295
( async ( ) => {
323
296
const stateFetchStartTime = performance . now ( ) ;
324
297
await this . stateAccountSubscriber . fetch ( ) ;
325
298
const stateFetchEndTime = performance . now ( ) ;
326
299
const stateFetchDuration = stateFetchEndTime - stateFetchStartTime ;
327
- console . log (
328
- `[PROFILING] State account fetch completed in ${ stateFetchDuration . toFixed (
329
- 2
330
- ) } ms`
331
- ) ;
332
300
} ) ( ) ,
333
301
] ) ;
334
302
335
- const parallelSubEndTime = performance . now ( ) ;
336
- const parallelSubDuration = parallelSubEndTime - parallelSubStartTime ;
337
- console . log (
338
- `[PROFILING] Parallel market and state subscriptions completed in ${ parallelSubDuration . toFixed (
339
- 2
340
- ) } ms`
341
- ) ;
342
-
343
303
const initialPerpMarketDataFromLatestData = new Map (
344
304
Array . from ( this . perpMarketAccountLatestData . values ( ) ) . map ( ( data ) => [
345
305
data . data . marketIndex ,
@@ -357,28 +317,9 @@ export class WebSocketDriftClientAccountSubscriberV2
357
317
358
318
this . eventEmitter . emit ( 'update' ) ;
359
319
360
- // Profile handleDelistedMarketOracles
361
- const handleDelistedStartTime = performance . now ( ) ;
362
320
await this . handleDelistedMarketOracles ( ) ;
363
- const handleDelistedEndTime = performance . now ( ) ;
364
- const handleDelistedDuration =
365
- handleDelistedEndTime - handleDelistedStartTime ;
366
- console . log (
367
- `[PROFILING] handleDelistedMarketOracles completed in ${ handleDelistedDuration . toFixed (
368
- 2
369
- ) } ms`
370
- ) ;
371
321
372
- // Profile oracle map setup
373
- const oracleMapStartTime = performance . now ( ) ;
374
322
await Promise . all ( [ this . setPerpOracleMap ( ) , this . setSpotOracleMap ( ) ] ) ;
375
- const oracleMapEndTime = performance . now ( ) ;
376
- const oracleMapDuration = oracleMapEndTime - oracleMapStartTime ;
377
- console . log (
378
- `[PROFILING] Oracle map setup completed in ${ oracleMapDuration . toFixed (
379
- 2
380
- ) } ms`
381
- ) ;
382
323
383
324
this . isSubscribing = false ;
384
325
this . isSubscribed = true ;
@@ -393,23 +334,6 @@ export class WebSocketDriftClientAccountSubscriberV2
393
334
2
394
335
) } ms`
395
336
) ;
396
- console . log (
397
- `[PROFILING] Breakdown: pubkeys=${ pubkeyDuration . toFixed (
398
- 2
399
- ) } ms, findAllMarkets=${ findAllMarketsDuration . toFixed (
400
- 2
401
- ) } ms, statePubkey=${ statePubkeyDuration . toFixed (
402
- 2
403
- ) } ms, parallelSubscriptions=${ parallelSubDuration . toFixed (
404
- 2
405
- // )}ms, setInitialData=${setInitialDataDuration.toFixed(
406
- // 2
407
- // )}ms, subscribeToOracles=${subscribeToOraclesDuration.toFixed(
408
- // 2
409
- ) } ms, handleDelisted=${ handleDelistedDuration . toFixed (
410
- 2
411
- ) } ms, oracleMap=${ oracleMapDuration . toFixed ( 2 ) } ms`
412
- ) ;
413
337
414
338
return true ;
415
339
}
0 commit comments