diff --git a/package.json b/package.json index 677651fe..9ec1a669 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "warp-contracts", - "version": "1.4.36-beta.10", + "version": "1.4.36-beta.13", "description": "An implementation of the SmartWeave smart contract protocol.", "types": "./lib/types/index.d.ts", "main": "./lib/cjs/index.js", diff --git a/src/cache/impl/LevelDbCache.ts b/src/cache/impl/LevelDbCache.ts index dc847a1e..4a23f6f3 100644 --- a/src/cache/impl/LevelDbCache.ts +++ b/src/cache/impl/LevelDbCache.ts @@ -7,6 +7,7 @@ import { SortKeyCacheRangeOptions } from '../SortKeyCacheRangeOptions'; import { AbstractSublevel, AbstractSublevelOptions } from 'abstract-level/types/abstract-sublevel'; import { AbstractChainedBatch } from 'abstract-level/types/abstract-chained-batch'; import { AbstractKeyIteratorOptions } from 'abstract-level/types/abstract-iterator'; +import { Benchmark } from '../../logging/Benchmark'; /** * The LevelDB is a lexicographically sorted key-value database - so it's ideal for this use case @@ -141,7 +142,10 @@ export class LevelDbCache implements SortKeyCache { } async put(stateCacheKey: CacheKey, value: V): Promise { - await this.setClientValue(stateCacheKey, new ClientValueWrapper(value)); + const putBenchmark = Benchmark.measure(); + this.setClientValue(stateCacheKey, new ClientValueWrapper(value)).then(); + putBenchmark.stop(); + this.logger.info('putBenchmark', putBenchmark.elapsed()); } /** @@ -158,14 +162,17 @@ export class LevelDbCache implements SortKeyCache { } private async setClientValue(stateCacheKey: CacheKey, valueWrapper: ClientValueWrapper): Promise { + const setClientValueBenchmark = Benchmark.measure(); this.validateKey(stateCacheKey.key); const contractCache = this.db.sublevel>(stateCacheKey.key, this.subLevelOptions); // manually opening to fix https://github.com/Level/level/issues/221 await contractCache.open(); - await contractCache.put(stateCacheKey.sortKey, valueWrapper); + contractCache.put(stateCacheKey.sortKey, valueWrapper).then(); if (this._rollbackBatch) { this._rollbackBatch.del(stateCacheKey.sortKey, { sublevel: contractCache }); } + setClientValueBenchmark.stop(); + this.logger.info('setClientValue', setClientValueBenchmark.elapsed()); } async delete(key: string): Promise { diff --git a/src/contract/states/ContractInteractionState.ts b/src/contract/states/ContractInteractionState.ts index 47d5d8cd..dd7e713c 100644 --- a/src/contract/states/ContractInteractionState.ts +++ b/src/contract/states/ContractInteractionState.ts @@ -147,9 +147,15 @@ export class ContractInteractionState implements InteractionState { forceStore = false ) { if (states.size > 1 || forceStore) { + const doStoreJsonLoopBenchmark = Benchmark.measure(); for (const [k, v] of states) { + const doStoreJsonSingularBenchmark = Benchmark.measure(); this._warp.stateEvaluator.putInCache(k, interaction, v).then(); + doStoreJsonSingularBenchmark.stop(); + this.logger.info(`doStoreJsonSingularBenchmark, ${k}`, doStoreJsonSingularBenchmark.elapsed()); } + doStoreJsonLoopBenchmark.stop(); + this.logger.info('doStoreJsonLoopBenchmark', doStoreJsonLoopBenchmark.elapsed()); } } diff --git a/src/core/modules/impl/CacheableStateEvaluator.ts b/src/core/modules/impl/CacheableStateEvaluator.ts index 1c0a22bf..746bfe9d 100644 --- a/src/core/modules/impl/CacheableStateEvaluator.ts +++ b/src/core/modules/impl/CacheableStateEvaluator.ts @@ -180,6 +180,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { transaction: GQLNodeInterface, state: EvalStateResult ): Promise { + const putInCacheBenchmark = Benchmark.measure(); if (transaction.dry) { return; } @@ -194,8 +195,13 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { sortKey: transaction.sortKey, dry: transaction.dry }); + putInCacheBenchmark.stop(); + this.cLogger.info('putInCacheBenchmark', putInCacheBenchmark.elapsed()); - await this.cache.put(new CacheKey(contractTxId, transaction.sortKey), stateToCache); + const putInCacheFunc = Benchmark.measure(); + this.cache.put(new CacheKey(contractTxId, transaction.sortKey), stateToCache).then(); + putInCacheFunc.stop(); + this.cLogger.info('putInCacheFunc', putInCacheFunc.elapsed()); } async syncState(