Author: stefan2
Date: Thu Sep 6 22:21:34 2012
New Revision: 1381785
URL: http://svn.apache.org/viewvc?rev=1381785&view=rev
Log:
Optimize replacing / updating handling in membuffer caches:
reduce the data churn by reusing the existing entry if possible.
* subversion/libsvn_subr/cache-membuffer.c
(membuffer_cache_set_internal): try to recycle the old entry
Modified:
subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
Modified: subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-membuffer.c?rev=1381785&r1=1381784&r2=1381785&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-membuffer.c Thu Sep 6
22:21:34 2012
@@ -1168,13 +1168,8 @@ membuffer_cache_set_internal(svn_membuff
&& cache->max_entry_size >= size
&& ensure_data_insertable(cache, size))
{
- /* Remove old data for this key, if that exists.
- * Get an unused entry for the key and and initialize it with
- * the serialized item's (future) posion within data buffer.
- */
- entry_t *entry = find_entry(cache, group_index, to_find, TRUE);
- entry->size = size;
- entry->offset = cache->current_data;
+ /* first, look for a previous entry for the given key */
+ entry_t *entry = find_entry(cache, group_index, to_find, FALSE);
#ifdef SVN_DEBUG_CACHE_MEMBUFFER
@@ -1185,14 +1180,32 @@ membuffer_cache_set_internal(svn_membuff
#endif
+ /* if there is an old version of that entry and the new data fits into
+ * the old spot, just re-use that space. */
+ if (entry && entry->size >= size)
+ {
+ entry->size = size;
+ }
+ else
+ {
+ /* Remove old data for this key, if that exists.
+ * Get an unused entry for the key and and initialize it with
+ * the serialized item's (future) posion within data buffer.
+ */
+ entry = find_entry(cache, group_index, to_find, TRUE);
+ entry->size = size;
+ entry->offset = cache->current_data;
+
+ /* Link the entry properly.
+ */
+ insert_entry(cache, entry);
+ }
+
/* Copy the serialized item data into the cache.
*/
if (size)
memcpy(cache->data + entry->offset, buffer, size);
- /* Link the entry properly.
- */
- insert_entry(cache, entry);
cache->total_writes++;
}
else