Skip to content

Commit

Permalink
Add an explanation on why we cache promisified functions (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado authored and s1na committed Sep 23, 2019
1 parent d0b5473 commit 3456922
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export default class VM extends AsyncEventEmitter {
this.allowUnlimitedContractSize =
opts.allowUnlimitedContractSize === undefined ? false : opts.allowUnlimitedContractSize

// We cache this promisified function as it's called from the main execution loop, and
// promisifying each time has a huge performance impact.
this._emit = promisify(this.emit.bind(this))
}

Expand Down
2 changes: 2 additions & 0 deletions lib/state/promisified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default class PStateManager {
constructor(wrapped: StateManager) {
this._wrapped = wrapped

// We cache these promisified function as they are called lots of times during the VM execution,
// and promisifying them each time has degrades its performance.
this.getAccount = promisify(this._wrapped.getAccount.bind(this._wrapped))

this.putAccount = promisify(this._wrapped.putAccount.bind(this._wrapped))
Expand Down

0 comments on commit 3456922

Please sign in to comment.