perf: REPLACE remove Flush + bulk build + deferred write = 1600x faster
Critical fix: REPLACE was calling area.Flush() after every field write! - gengo gen_cmd.go: removed Flush() from emitReplaceCmd - Harbour defers write until DBCOMMIT/CLOSE/GoTo, not per-REPLACE Combined with bulk build + deferred APPEND: - B1 APPEND 10K: 72,228ms → 30ms (2,400x improvement!) - B2 INDEX NAME: 34ms → 5ms (6.8x improvement) - Harbour comparison: Five 30ms vs Harbour 27ms (1.1x) Also: OrderCreate flushes dirty record + EOF + header before index build Benchmark on ext4 (home dir): ┌─────────────┬──────────┬────────┬───────┐ │ Benchmark │ Harbour │ Five │ Ratio │ ├─────────────┼──────────┼────────┼───────┤ │ APPEND 10K │ 27ms │ 30ms │ 1.1x │ │ INDEX NAME │ 2ms │ 5ms │ 2.5x │ │ INDEX CITY │ 0ms │ 7ms │ - │ │ SEEK 10K │ 6ms │ 25ms │ 4.2x │ │ SCAN FWD │ 1ms │ 6ms │ 6x │ │ SCAN BWD │ 0ms │ 6ms │ - │ │ PACK │ 4ms │ 3ms │ 0.75x │ └─────────────┴──────────┴────────┴───────┘ Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -132,7 +132,8 @@ func (g *Generator) emitReplaceCmd(s *ast.ReplaceCmd, locals localMap) {
|
||||
g.writeln("}")
|
||||
}
|
||||
}
|
||||
g.writeln("area.Flush()")
|
||||
// No Flush here — Harbour defers write until DBCOMMIT/CLOSE/GoTo.
|
||||
// PutValue sets dirty flag; flushRecord writes on next GoTo or Close.
|
||||
|
||||
g.indent--
|
||||
g.writeln("}")
|
||||
|
||||
@@ -63,6 +63,13 @@ func (a *DBFArea) ensureIndexState() {
|
||||
func (a *DBFArea) OrderCreate(params hbrdd.OrderCreateParams) error {
|
||||
a.ensureIndexState()
|
||||
|
||||
// Flush pending record + update header/EOF before index build
|
||||
if a.dirty {
|
||||
a.flushRecord()
|
||||
}
|
||||
a.dataFile.WriteAt([]byte{EOFMarker}, a.header.EOFOffset())
|
||||
a.updateHeader()
|
||||
|
||||
// Disable indexed navigation during key evaluation (GoTo must use natural order)
|
||||
a.idxState.current = -1
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ func CreateIndex(path string, keyExpr string, keyLen int, unique bool, descend b
|
||||
seps[j].recNo = binary.LittleEndian.Uint32(childPg[lastOff+4 : lastOff+8])
|
||||
seps[j].key = make([]byte, keyLen)
|
||||
copy(seps[j].key, childPg[lastOff+8:lastOff+8+keyLen])
|
||||
// Only remove from leaf pages — interior separators stay
|
||||
// Remove from leaf only (interior separators stay as routing keys)
|
||||
if isLeafLevel {
|
||||
binary.LittleEndian.PutUint16(childPg[0:2], uint16(childCnt-1))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user