Branch: Tag:

2017-02-23

2017-02-23 13:45:15 by Martin Karlgren <marty@roxen.com>

Cache manager_size_overhead when entries aren't added.

The overhead will be recomputed when the number of added entries since the last
computation is above 10% of the total number of entries in the cache.

192:    //! For functions in this class, a @[CacheStats] object does not    //! exist only due to race, so the cache should just be ignored.    +  int cached_overhead_add_count; +  //! Snapshot of @[entry_add_count] at the point the manager overhead +  //! was computed. +  +  int cached_overhead; +  //! Cached manager overhead. Recomputed in manager_size_overhead(). +     //! @decl program CacheEntry;    //!    //! The manager-specific class to use to create @[CacheEntry] objects.
322:    //! Returns the size consumed by the manager itself, excluding the    //! cache entries.    { +  // Return the cached overhead as long as the number of added +  // entries since the last computation is less than 10% of the +  // number of entries in the cache. The cache is a workaround for +  // the horrific performance of Pike.count_memory (-1, m) on large +  // mappings (addressed in Pike 8.1). +  int num_entries; +  foreach (stats;; CacheStats stats) { +  if (stats) num_entries += stats->count; +  } +  +  if ((entry_add_count - cached_overhead_add_count) < +  (num_entries / 10)) +  return cached_overhead; +     int res = (Pike.count_memory (-1, this, lookup) +    Pike.count_memory (0, stats));    foreach (lookup;; mapping(mixed:CacheEntry) lm)    res += Pike.count_memory (-1, lm); -  +  +  cached_overhead_add_count = entry_add_count; +  cached_overhead = res;    return res;    }