localForage icon indicating copy to clipboard operation
localForage copied to clipboard

Less `.catch(reject)` -> less in mem promises in IndexedDb driver

Open duzun opened this issue 4 years ago • 0 comments

This PR is a small pattern change in indexeddb.js that should result a an unnoticeable performance improvement, by having one less promise instance in memory at a given moment in time for each method call on the driver.

This also removes the unnecessary call to .catch(reject).

The old pattern:

var promise = new Promise(function (resolve, reject) {
	self
      	.ready()
      	.then(function() {
		  // ...
	  	})
		.catch(reject);
	});

The new pattern:

var promise = self
      .ready()
      .then(function() {
          return new Promise(function (resolve, reject) {
		  // ...
	  });
  });

The new Promise is created after instance.ready() has resolved, thus delayed, thus existing in mem for a shorter period of time.

duzun avatar Aug 19 '21 17:08 duzun