Bug 1389381 - Part 3: Loop over the entire set iterator when truncating a LimitedSet. r=aswan, a=sledru FENNEC_55_0_2_BUILD1 FENNEC_55_0_2_RELEASE FIREFOX_55_0_2_BUILD1 FIREFOX_55_0_2_RELEASE
authorKris Maglione <maglione.k@gmail.com>
Fri, 11 Aug 2017 14:46:44 -0700
changeset 414535 45ab6e362747102d00fd75378727fcddcfd35f44
parent 414534 1b2c15264aee18d2ff1f65015cc26ef2f64fc762
child 414536 d801af9d45e53ba5a5655e32ec889cd18aa8a247
push id1507
push userryanvm@gmail.com
push dateMon, 14 Aug 2017 14:29:17 +0000
treeherdermozilla-release@45ab6e362747 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, sledru
bugs1389381
milestone55.0.2
Bug 1389381 - Part 3: Loop over the entire set iterator when truncating a LimitedSet. r=aswan, a=sledru MozReview-Commit-ID: 3imHF9IRI2N
toolkit/components/extensions/ExtensionUtils.jsm
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -258,20 +258,24 @@ class LimitedSet extends Set {
   constructor(limit, slop = Math.round(limit * .25), iterable = undefined) {
     super(iterable);
     this.limit = limit;
     this.slop = slop;
   }
 
   truncate(limit) {
     for (let item of this) {
-      if (this.size <= limit) {
-        break;
+      // Live set iterators can ge relatively expensive, since they need
+      // to be updated after every modification to the set. Since
+      // breaking out of the loop early will keep the iterator alive
+      // until the next full GC, we're currently better off finishing
+      // the entire loop even after we're done truncating.
+      if (this.size > limit) {
+        this.delete(item);
       }
-      this.delete(item);
     }
   }
 
   add(item) {
     if (!this.has(item) && this.size >= this.limit + this.slop) {
       this.truncate(this.limit - 1);
     }
     super.add(item);