@@ -16,16 +16,16 @@ import (
1616// deleting components, and a combined workload of setting and retrieving.
1717//
1818// Results show that the in-memory cache is generally faster than the file-based cache,
19- // especially for write operations like Set . Here's a summary of the performance comparison:
19+ // especially for write operations like SetComponent . Here's a summary of the performance comparison:
2020//
21- // 1. Set : In-memory is ~60x faster than file-based
22- // 2. Children : In-memory is ~1.1x faster than file-based
23- // 3. Delete : In-memory is ~1.6x faster than file-based
24- // 4. SetAndChildren : In-memory is ~3.4x faster than file-based
21+ // 1. SetComponent : In-memory is ~60x faster than file-based
22+ // 2. ComponentChildren : In-memory is ~1.1x faster than file-based
23+ // 3. DeleteComponent : In-memory is ~1.6x faster than file-based
24+ // 4. SetComponentAndComponentChildren AndChildren : In-memory is ~3.4x faster than file-based
2525//
26- // The performance difference is most significant for write operations (Set )
26+ // The performance difference is most significant for write operations (SetComponent )
2727// because file-based operations involve disk I/O, which is much slower than memory access.
28- // Read operations (Children ) show a smaller performance gap because SQLite's query
28+ // Read operations (ComponentChildren ) show a smaller performance gap because SQLite's query
2929// optimization works well for both storage modes.
3030
3131const (
@@ -50,7 +50,7 @@ func setupTestData(b *testing.B, cache *db.ComponentCache) {
5050 State : & state ,
5151 }
5252
53- err := cache .Set (rootComponent )
53+ err := cache .SetComponent (rootComponent )
5454 require .NoError (b , err )
5555
5656 // Create 10 first-level children
@@ -67,7 +67,7 @@ func setupTestData(b *testing.B, cache *db.ComponentCache) {
6767 State : & state ,
6868 }
6969
70- err := cache .Set (component )
70+ err := cache .SetComponent (component )
7171 require .NoError (b , err )
7272
7373 // Create 5 second-level children for each first-level child
@@ -84,7 +84,7 @@ func setupTestData(b *testing.B, cache *db.ComponentCache) {
8484 State : & state ,
8585 }
8686
87- err := cache .Set (childComponent )
87+ err := cache .SetComponent (childComponent )
8888 require .NoError (b , err )
8989
9090 // Create 3 third-level children for each second-level child
@@ -101,7 +101,7 @@ func setupTestData(b *testing.B, cache *db.ComponentCache) {
101101 State : & state ,
102102 }
103103
104- err := cache .Set (grandchildComponent )
104+ err := cache .SetComponent (grandchildComponent )
105105 require .NoError (b , err )
106106 }
107107 }
@@ -122,8 +122,8 @@ func BenchmarkMemoryCache(b *testing.B) {
122122 cache := db .GetComponentCache ()
123123 defer cache .Close ()
124124
125- // Run the Set benchmark
126- b .Run ("Set " , func (b * testing.B ) {
125+ // Run the SetComponent benchmark
126+ b .Run ("SetComponent " , func (b * testing.B ) {
127127 state := client .ComponentState ("Healthy" )
128128 group := testGroup
129129 namespace := testNamespace
@@ -143,39 +143,39 @@ func BenchmarkMemoryCache(b *testing.B) {
143143 }
144144 i ++
145145
146- err := cache .Set (component )
146+ err := cache .SetComponent (component )
147147 require .NoError (b , err )
148148 }
149149 })
150150
151151 // Setup test data for the remaining benchmarks
152152 setupTestData (b , cache )
153153
154- // Run the Children benchmark
155- b .Run ("Children " , func (b * testing.B ) {
154+ // Run the ComponentChildren benchmark
155+ b .Run ("ComponentChildren " , func (b * testing.B ) {
156156 b .ResetTimer ()
157157 for b .Loop () {
158- children , err := cache .Children ("root-uid" )
158+ children , err := cache .ComponentChildren ("root-uid" )
159159 require .NoError (b , err )
160160 require .NotEmpty (b , children )
161161 }
162162 })
163163
164- // Run the Delete benchmark
165- b .Run ("Delete " , func (b * testing.B ) {
164+ // Run the DeleteComponent benchmark
165+ b .Run ("DeleteComponent " , func (b * testing.B ) {
166166 b .ResetTimer ()
167167 for i := 0 ; i < b .N ; i ++ {
168- // Delete a level 1 component (which should cascade to its children)
169- err := cache .Delete ("level1-uid-" + string (rune ('a' + i % 10 )))
168+ // DeleteComponent a level 1 component (which should cascade to its children)
169+ err := cache .DeleteComponent ("level1-uid-" + string (rune ('a' + i % 10 )))
170170 require .NoError (b , err )
171171 }
172172 })
173173
174174 // Setup test data again for the combined benchmark
175175 setupTestData (b , cache )
176176
177- // Run the SetAndChildren benchmark
178- b .Run ("SetAndChildren " , func (b * testing.B ) {
177+ // Run the SetComponentAndComponentChildren benchmark
178+ b .Run ("SetComponentAndComponentChildren " , func (b * testing.B ) {
179179 state := client .ComponentState ("Healthy" )
180180 group := testGroup
181181 namespace := testNamespace
@@ -196,11 +196,11 @@ func BenchmarkMemoryCache(b *testing.B) {
196196 State : & state ,
197197 }
198198
199- err := cache .Set (component )
199+ err := cache .SetComponent (component )
200200 require .NoError (b , err )
201201
202202 // Retrieve children
203- children , err := cache .Children ("root-uid" )
203+ children , err := cache .ComponentChildren ("root-uid" )
204204 require .NoError (b , err )
205205 require .NotEmpty (b , children )
206206 }
@@ -227,8 +227,8 @@ func BenchmarkFileCache(b *testing.B) {
227227 _ = os .Remove (benchDBFile )
228228 }()
229229
230- // Run the Set benchmark
231- b .Run ("Set " , func (b * testing.B ) {
230+ // Run the SetComponent benchmark
231+ b .Run ("SetComponent " , func (b * testing.B ) {
232232 state := client .ComponentState ("Healthy" )
233233 group := testGroup
234234 namespace := testNamespace
@@ -246,30 +246,30 @@ func BenchmarkFileCache(b *testing.B) {
246246 State : & state ,
247247 }
248248
249- err := cache .Set (component )
249+ err := cache .SetComponent (component )
250250 require .NoError (b , err )
251251 }
252252 })
253253
254254 // Setup test data for the remaining benchmarks
255255 setupTestData (b , cache )
256256
257- // Run the Children benchmark
258- b .Run ("Children " , func (b * testing.B ) {
257+ // Run the ComponentChildren benchmark
258+ b .Run ("ComponentChildren " , func (b * testing.B ) {
259259 b .ResetTimer ()
260260 for i := 0 ; i < b .N ; i ++ {
261- children , err := cache .Children ("root-uid" )
261+ children , err := cache .ComponentChildren ("root-uid" )
262262 require .NoError (b , err )
263263 require .NotEmpty (b , children )
264264 }
265265 })
266266
267- // Run the Delete benchmark
268- b .Run ("Delete " , func (b * testing.B ) {
267+ // Run the DeleteComponent benchmark
268+ b .Run ("DeleteComponent " , func (b * testing.B ) {
269269 b .ResetTimer ()
270270 for i := 0 ; i < b .N ; i ++ {
271- // Delete a level 1 component (which should cascade to its children)
272- err := cache .Delete ("level1-uid-" + string (rune ('a' + i % 10 )))
271+ // DeleteComponent a level 1 component (which should cascade to its children)
272+ err := cache .DeleteComponent ("level1-uid-" + string (rune ('a' + i % 10 )))
273273 require .NoError (b , err )
274274 }
275275 })
@@ -299,11 +299,11 @@ func BenchmarkFileCache(b *testing.B) {
299299 State : & state ,
300300 }
301301
302- err := cache .Set (component )
302+ err := cache .SetComponent (component )
303303 require .NoError (b , err )
304304
305305 // Retrieve children
306- children , err := cache .Children ("root-uid" )
306+ children , err := cache .ComponentChildren ("root-uid" )
307307 require .NoError (b , err )
308308 require .NotEmpty (b , children )
309309 }
0 commit comments