From e4c744843e740e74b824c43950b1961736ccb8ad Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Sun, 19 Apr 2026 14:25:13 +0200 Subject: change Store.Insert() to take arguments by pointer This increases memory overhead slightly, but when converting Gorp uses into Oblast, I saw that there is a legitimate risk of just ignoring the result value and continuing with the unupdated records. So according to the design priorities that I myself laid down, I'm sacrificing some performance for safety of use. --- benchmark/benchmark_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'benchmark') diff --git a/benchmark/benchmark_test.go b/benchmark/benchmark_test.go index ada238e..d18c0cb 100644 --- a/benchmark/benchmark_test.go +++ b/benchmark/benchmark_test.go @@ -268,10 +268,12 @@ func BenchmarkInsertAndDelete(b *testing.B) { // prepare the functions that will be benched insertAndDeleteWithOblast := func(b *testing.B) { records := make([]OblastEntry, batchSize) + recordsForInsert := make([]*OblastEntry, batchSize) for idx := range records { records[idx] = OblastEntry{Message: "hello"} + recordsForInsert[idx] = &records[idx] } - records = must.Return(store.Insert(db, records...))(b) + must.Succeed(b, store.Insert(db, recordsForInsert...)) for _, r := range records { if r.ID == 0 { b.Errorf("ID was not filled!") @@ -388,10 +390,12 @@ func BenchmarkUpdate(b *testing.B) { // prepare a bunch of records that we can update, in a reproducible way _ = must.Return(db.Exec(`DELETE FROM entries`)) recordsForOblast := make([]OblastEntry, batchSize) + recordsForOblastForInsert := make([]*OblastEntry, batchSize) for idx := range recordsForOblast { recordsForOblast[idx] = OblastEntry{Message: "hello"} + recordsForOblastForInsert[idx] = &recordsForOblast[idx] } - recordsForOblast = must.Return(store.Insert(db, recordsForOblast...))(b) + must.Succeed(b, store.Insert(db, recordsForOblastForInsert...)) recordsForGorp := make([]any, batchSize) for idx, r := range recordsForOblast { recordsForGorp[idx] = new(GorpEntry(r)) -- cgit v1.2.3