Fossil SCM

***FIXME TEST*** - do not commit to trunk ***FIXME TEST*** Make the total size and total number of entries in the content cache optionally set from an environent variable. This is for testing so we can get an idea of optimal numbers, however, the cache needs to be redesigned so this is (a) a short-term minimally intrusive performance fix and (b) experimentation to help with a resdesign.

danshearer 2026-08-22 06:48 UTC cache-speedups
Commit 8424663f26d776be41a2bde44f5acd32db3f4a6a451fc1ef98a30c7d6e0d125e
1 file changed +31 -2
+31 -2
--- src/content.c
+++ src/content.c
@@ -22,10 +22,13 @@
2222
#include <assert.h>
2323
2424
/*
2525
** The artifact retrieval cache
2626
*/
27
+static int cacheMaxN = 0; /* Max cache entries */
28
+static i64 cacheMaxSz = 0; /* Max cache bytes */
29
+
2730
static struct {
2831
i64 szTotal; /* Total size of all entries in the cache */
2932
int n; /* Current number of cache entries */
3033
int nAlloc; /* Number of slots allocated in a[] */
3134
int nextAge; /* Age counter for implementing LRU */
@@ -77,16 +80,42 @@
7780
** This routines hands responsibility for the artifact over to the cache.
7881
** The cache will deallocate memory when it has finished with it.
7982
*/
8083
void content_cache_insert(int rid, Blob *pBlob){
8184
struct cacheLine *p;
82
- if( contentCache.n>500 || contentCache.szTotal>50000000 ){
85
+
86
+ if( cacheMaxN==0 ){ /* FIXME TEST Not to be merged to trunk FIXME */
87
+ const char *z;
88
+
89
+ cacheMaxN = 500; /* old hardcoded value */
90
+ z = getenv("FOSSIL_CACHE_N");
91
+ if( z!=0 ){
92
+ int val = atoi(z);
93
+ if( val>0 ) cacheMaxN = val;
94
+ }
95
+
96
+ cacheMaxSz = (i64)50000000; /*old hardcoded value */
97
+ z = getenv("FOSSIL_CACHE_SZ");
98
+ if( z!=0 ){
99
+ i64 val = (i64)atoll(z);
100
+ if( val>0 ) cacheMaxSz = val;
101
+ }
102
+ }
103
+
104
+ if( cacheMaxN==0 ){
105
+ const char *z;
106
+ z = getenv("FOSSIL_CACHE_N");
107
+ cacheMaxN = (z!=0 && atoi(z)>0) ? atoi(z) : 500;
108
+ z = getenv("FOSSIL_CACHE_SZ");
109
+ cacheMaxSz = (z!=0 && atoll(z)>0) ? (i64)atoll(z) : (i64)50000000;
110
+ }
111
+ if( contentCache.n>cacheMaxN || contentCache.szTotal>cacheMaxSz ){
83112
i64 szBefore;
84113
do{
85114
szBefore = contentCache.szTotal;
86115
content_cache_expire_oldest();
87
- }while( contentCache.szTotal>50000000 && contentCache.szTotal<szBefore );
116
+ }while( contentCache.szTotal>cacheMaxSz && contentCache.szTotal<szBefore );
88117
}
89118
if( contentCache.n>=contentCache.nAlloc ){
90119
contentCache.nAlloc = contentCache.nAlloc*2 + 10;
91120
contentCache.a = fossil_realloc(contentCache.a,
92121
contentCache.nAlloc*sizeof(contentCache.a[0]));
93122
--- src/content.c
+++ src/content.c
@@ -22,10 +22,13 @@
22 #include <assert.h>
23
24 /*
25 ** The artifact retrieval cache
26 */
 
 
 
27 static struct {
28 i64 szTotal; /* Total size of all entries in the cache */
29 int n; /* Current number of cache entries */
30 int nAlloc; /* Number of slots allocated in a[] */
31 int nextAge; /* Age counter for implementing LRU */
@@ -77,16 +80,42 @@
77 ** This routines hands responsibility for the artifact over to the cache.
78 ** The cache will deallocate memory when it has finished with it.
79 */
80 void content_cache_insert(int rid, Blob *pBlob){
81 struct cacheLine *p;
82 if( contentCache.n>500 || contentCache.szTotal>50000000 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83 i64 szBefore;
84 do{
85 szBefore = contentCache.szTotal;
86 content_cache_expire_oldest();
87 }while( contentCache.szTotal>50000000 && contentCache.szTotal<szBefore );
88 }
89 if( contentCache.n>=contentCache.nAlloc ){
90 contentCache.nAlloc = contentCache.nAlloc*2 + 10;
91 contentCache.a = fossil_realloc(contentCache.a,
92 contentCache.nAlloc*sizeof(contentCache.a[0]));
93
--- src/content.c
+++ src/content.c
@@ -22,10 +22,13 @@
22 #include <assert.h>
23
24 /*
25 ** The artifact retrieval cache
26 */
27 static int cacheMaxN = 0; /* Max cache entries */
28 static i64 cacheMaxSz = 0; /* Max cache bytes */
29
30 static struct {
31 i64 szTotal; /* Total size of all entries in the cache */
32 int n; /* Current number of cache entries */
33 int nAlloc; /* Number of slots allocated in a[] */
34 int nextAge; /* Age counter for implementing LRU */
@@ -77,16 +80,42 @@
80 ** This routines hands responsibility for the artifact over to the cache.
81 ** The cache will deallocate memory when it has finished with it.
82 */
83 void content_cache_insert(int rid, Blob *pBlob){
84 struct cacheLine *p;
85
86 if( cacheMaxN==0 ){ /* FIXME TEST Not to be merged to trunk FIXME */
87 const char *z;
88
89 cacheMaxN = 500; /* old hardcoded value */
90 z = getenv("FOSSIL_CACHE_N");
91 if( z!=0 ){
92 int val = atoi(z);
93 if( val>0 ) cacheMaxN = val;
94 }
95
96 cacheMaxSz = (i64)50000000; /*old hardcoded value */
97 z = getenv("FOSSIL_CACHE_SZ");
98 if( z!=0 ){
99 i64 val = (i64)atoll(z);
100 if( val>0 ) cacheMaxSz = val;
101 }
102 }
103
104 if( cacheMaxN==0 ){
105 const char *z;
106 z = getenv("FOSSIL_CACHE_N");
107 cacheMaxN = (z!=0 && atoi(z)>0) ? atoi(z) : 500;
108 z = getenv("FOSSIL_CACHE_SZ");
109 cacheMaxSz = (z!=0 && atoll(z)>0) ? (i64)atoll(z) : (i64)50000000;
110 }
111 if( contentCache.n>cacheMaxN || contentCache.szTotal>cacheMaxSz ){
112 i64 szBefore;
113 do{
114 szBefore = contentCache.szTotal;
115 content_cache_expire_oldest();
116 }while( contentCache.szTotal>cacheMaxSz && contentCache.szTotal<szBefore );
117 }
118 if( contentCache.n>=contentCache.nAlloc ){
119 contentCache.nAlloc = contentCache.nAlloc*2 + 10;
120 contentCache.a = fossil_realloc(contentCache.a,
121 contentCache.nAlloc*sizeof(contentCache.a[0]));
122

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button