MCPcopy Index your code
hub / github.com/codechenx/FastTableViewer / TestStringInterningMemorySavings

Function TestStringInterningMemorySavings

string_interning_test.go:142–188  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

140}
141
142func TestStringInterningMemorySavings(t *testing.T) {
143 // Create large dataset with repeated values
144 numRows := 10000
145 categories := []string{"Active", "Inactive", "Pending", "Completed", "Failed"}
146
147 data := [][]string{{"Status", "ID"}}
148 for i := 0; i < numRows; i++ {
149 data = append(data, []string{
150 categories[i%len(categories)],
151 fmt.Sprintf("%d", i),
152 })
153 }
154
155 // Create buffer without interning
156 runtime.GC()
157 var m1 runtime.MemStats
158 runtime.ReadMemStats(&m1)
159
160 b1, _ := createNewBufferWithData(data, false)
161 b1.rowFreeze = 1
162
163 var m2 runtime.MemStats
164 runtime.ReadMemStats(&m2)
165 memWithoutInterning := m2.Alloc - m1.Alloc
166
167 // Create buffer with interning
168 runtime.GC()
169 var m3 runtime.MemStats
170 runtime.ReadMemStats(&m3)
171
172 b2, _ := createNewBufferWithData(data, false)
173 b2.rowFreeze = 1
174 b2.enableStringInterning()
175
176 var m4 runtime.MemStats
177 runtime.ReadMemStats(&m4)
178 memWithInterning := m4.Alloc - m3.Alloc
179
180 t.Logf("Memory without interning: %d bytes", memWithoutInterning)
181 t.Logf("Memory with interning: %d bytes", memWithInterning)
182
183 // Interning should use less memory (though the difference might be small in test)
184 // We're mainly testing that it doesn't crash and completes successfully
185 if b2.internCols == nil {
186 t.Error("Interning structures should be initialized")
187 }
188}
189
190func TestInternValue(t *testing.T) {
191 b := createNewBuffer()

Callers

nothing calls this directly

Calls 2

createNewBufferWithDataFunction · 0.85
enableStringInterningMethod · 0.80

Tested by

no test coverage detected