Skip to content

Commit 60a5ddd

Browse files
yokoflyclaude
andcommitted
perf(proton): remove g.Debug() calls on nil values in batch insert hot loop
Remove 37 g.Debug() calls that fired for every nil value in every row. g.Debug() calls runtime.Caller() for stack walking + string formatting + zerolog event creation on each invocation. With -d flag enabled, 10 nullable columns, and 1.66M rows, this generated millions of expensive debug calls that provided zero diagnostic value (nil is normal for nullable columns). Benchmark (localhost, 1.66M rows, batch_limit=50K, cumulative): Baseline: 62s (41s user, 77% CPU) + LZ4: 61s + this: 28s (10s user, 40% CPU) ← 54% faster, biggest single win Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent a9affc1 commit 60a5ddd

File tree

1 file changed

+0
-74
lines changed

1 file changed

+0
-74
lines changed

core/dbio/database/database_proton.go

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -467,53 +467,41 @@ func (conn *ProtonConn) processBatch(tableFName string, table Table, batch *iop.
467467
row[colI] = val
468468
}
469469
eG.Capture(err)
470-
} else {
471-
g.Debug("decimal if value == nil")
472470
}
473471
}
474472

475473
for _, colI := range booleanCols {
476474
if row[colI] != nil {
477475
row[colI], err = cast.ToBoolE(row[colI])
478476
eG.Capture(err)
479-
} else {
480-
g.Debug("boolean if value == nil")
481477
}
482478
}
483479

484480
for _, colI := range stringCols {
485481
if row[colI] != nil {
486482
row[colI], err = cast.ToStringE(row[colI])
487483
eG.Capture(err)
488-
} else {
489-
g.Debug("string if value == nil")
490484
}
491485
}
492486

493487
for _, colI := range int8Cols {
494488
if row[colI] != nil {
495489
row[colI], err = cast.ToInt8E(row[colI])
496490
eG.Capture(err)
497-
} else {
498-
g.Debug("int8 if value == nil")
499491
}
500492
}
501493

502494
for _, colI := range int16Cols {
503495
if row[colI] != nil {
504496
row[colI], err = cast.ToInt16E(row[colI])
505497
eG.Capture(err)
506-
} else {
507-
g.Debug("int16 if value == nil")
508498
}
509499
}
510500

511501
for _, colI := range int32Cols {
512502
if row[colI] != nil {
513503
row[colI], err = cast.ToInt32E(row[colI])
514504
eG.Capture(err)
515-
} else {
516-
g.Debug("int32 if value == nil")
517505
}
518506
}
519507

@@ -522,8 +510,6 @@ func (conn *ProtonConn) processBatch(tableFName string, table Table, batch *iop.
522510
if row[colI] != nil {
523511
row[colI], err = cast.ToIntE(row[colI])
524512
eG.Capture(err)
525-
} else {
526-
g.Debug("int if value == nil")
527513
}
528514
}
529515

@@ -532,26 +518,20 @@ func (conn *ProtonConn) processBatch(tableFName string, table Table, batch *iop.
532518
if row[colI] != nil {
533519
row[colI], err = cast.ToInt64E(row[colI])
534520
eG.Capture(err)
535-
} else {
536-
g.Debug("int64 if value == nil")
537521
}
538522
}
539523

540524
for _, colI := range uint8Cols {
541525
if row[colI] != nil {
542526
row[colI], err = cast.ToUint8E(row[colI])
543527
eG.Capture(err)
544-
} else {
545-
g.Debug("uint8 if value == nil")
546528
}
547529
}
548530

549531
for _, colI := range uint16Cols {
550532
if row[colI] != nil {
551533
row[colI], err = cast.ToUint16E(row[colI])
552534
eG.Capture(err)
553-
} else {
554-
g.Debug("uint16 if value == nil")
555535
}
556536
}
557537

@@ -560,8 +540,6 @@ func (conn *ProtonConn) processBatch(tableFName string, table Table, batch *iop.
560540
if row[colI] != nil {
561541
row[colI], err = cast.ToUint32E(row[colI])
562542
eG.Capture(err)
563-
} else {
564-
g.Debug("uint32 if value == nil")
565543
}
566544
}
567545

@@ -570,8 +548,6 @@ func (conn *ProtonConn) processBatch(tableFName string, table Table, batch *iop.
570548
if row[colI] != nil {
571549
row[colI], err = cast.ToUint64E(row[colI])
572550
eG.Capture(err)
573-
} else {
574-
g.Debug("uint64 if value == nil")
575551
}
576552
}
577553

@@ -580,224 +556,174 @@ func (conn *ProtonConn) processBatch(tableFName string, table Table, batch *iop.
580556
if row[colI] != nil {
581557
row[colI], err = cast.ToFloat64E(row[colI])
582558
eG.Capture(err)
583-
} else {
584-
g.Debug("float64 if value == nil")
585559
}
586560
}
587561

588562
for _, colI := range float32Cols {
589563
if row[colI] != nil {
590564
row[colI], err = cast.ToFloat32E(row[colI])
591565
eG.Capture(err)
592-
} else {
593-
g.Debug("float32 if value == nil")
594566
}
595567
}
596568

597569
for _, colI := range float64Cols {
598570
if row[colI] != nil {
599571
row[colI], err = cast.ToFloat64E(row[colI])
600572
eG.Capture(err)
601-
} else {
602-
g.Debug("float64 if value == nil")
603573
}
604574
}
605575

606576
for _, colI := range arrayStringCols {
607577
if row[colI] != nil {
608578
row[colI], err = conn.convertToArrayString(row[colI])
609579
eG.Capture(err)
610-
} else {
611-
g.Debug("empty arraystring if value == nil")
612580
}
613581
}
614582

615583
for _, colI := range arrayBooleanCols {
616584
if row[colI] != nil {
617585
row[colI], err = conn.convertToArrayBool(row[colI])
618586
eG.Capture(err)
619-
} else {
620-
g.Debug("empty arrayboolean if value == nil")
621587
}
622588
}
623589

624590
for _, colI := range arrayInt8Cols {
625591
if row[colI] != nil {
626592
row[colI], err = conn.convertToArrayInt8(row[colI])
627593
eG.Capture(err)
628-
} else {
629-
g.Debug("empty arrayint8 if value == nil")
630594
}
631595
}
632596

633597
for _, colI := range arrayInt16Cols {
634598
if row[colI] != nil {
635599
row[colI], err = conn.convertToArrayInt16(row[colI])
636600
eG.Capture(err)
637-
} else {
638-
g.Debug("empty arrayint16 if value == nil")
639601
}
640602
}
641603

642604
for _, colI := range arrayInt32Cols {
643605
if row[colI] != nil {
644606
row[colI], err = conn.convertToArrayInt32(row[colI])
645607
eG.Capture(err)
646-
} else {
647-
g.Debug("empty arrayint32 if value == nil")
648608
}
649609
}
650610

651611
for _, colI := range arrayInt64Cols {
652612
if row[colI] != nil {
653613
row[colI], err = conn.convertToArrayInt64(row[colI])
654614
eG.Capture(err)
655-
} else {
656-
g.Debug("empty arrayint64 if value == nil")
657615
}
658616
}
659617

660618
for _, colI := range arrayUint8Cols {
661619
if row[colI] != nil {
662620
row[colI], err = conn.convertToArrayUint8(row[colI])
663621
eG.Capture(err)
664-
} else {
665-
g.Debug("empty arrayuint8 if value == nil")
666622
}
667623
}
668624

669625
for _, colI := range arrayUint16Cols {
670626
if row[colI] != nil {
671627
row[colI], err = conn.convertToArrayUint16(row[colI])
672628
eG.Capture(err)
673-
} else {
674-
g.Debug("empty arrayuint16 if value == nil")
675629
}
676630
}
677631

678632
for _, colI := range arrayUint32Cols {
679633
if row[colI] != nil {
680634
row[colI], err = conn.convertToArrayUint32(row[colI])
681635
eG.Capture(err)
682-
} else {
683-
g.Debug("empty arrayuint32 if value == nil")
684636
}
685637
}
686638

687639
for _, colI := range arrayUint64Cols {
688640
if row[colI] != nil {
689641
row[colI], err = conn.convertToArrayUint64(row[colI])
690642
eG.Capture(err)
691-
} else {
692-
g.Debug("empty arrayuint64 if value == nil")
693643
}
694644
}
695645

696646
for _, colI := range arrayFloat32Cols {
697647
if row[colI] != nil {
698648
row[colI], err = conn.convertToArrayFloat32(row[colI])
699649
eG.Capture(err)
700-
} else {
701-
g.Debug("empty arrayfloat32 if value == nil")
702650
}
703651
}
704652

705653
for _, colI := range arrayFloat64Cols {
706654
if row[colI] != nil {
707655
row[colI], err = conn.convertToArrayFloat64(row[colI])
708656
eG.Capture(err)
709-
} else {
710-
g.Debug("empty arrayfloat64 if value == nil")
711657
}
712658
}
713659

714660
for _, colI := range mapStringStringCols {
715661
if row[colI] != nil {
716662
row[colI], err = conn.convertToMapStringString(row[colI])
717663
eG.Capture(err)
718-
} else {
719-
g.Debug("empty mapstringstring if value == nil")
720664
}
721665
}
722666

723667
for _, colI := range mapStringInt32Cols {
724668
if row[colI] != nil {
725669
row[colI], err = conn.convertToMapStringInt32(row[colI])
726670
eG.Capture(err)
727-
} else {
728-
g.Debug("empty mapstringint32 if value == nil")
729671
}
730672
}
731673

732674
for _, colI := range mapStringInt64Cols {
733675
if row[colI] != nil {
734676
row[colI], err = conn.convertToMapStringInt64(row[colI])
735677
eG.Capture(err)
736-
} else {
737-
g.Debug("empty mapstringint64 if value == nil")
738678
}
739679
}
740680

741681
for _, colI := range mapStringUint32Cols {
742682
if row[colI] != nil {
743683
row[colI], err = conn.convertToMapStringUint32(row[colI])
744684
eG.Capture(err)
745-
} else {
746-
g.Debug("empty mapstringuint32 if value == nil")
747685
}
748686
}
749687

750688
for _, colI := range mapStringUint64Cols {
751689
if row[colI] != nil {
752690
row[colI], err = conn.convertToMapStringUint64(row[colI])
753691
eG.Capture(err)
754-
} else {
755-
g.Debug("empty mapstringuint64 if value == nil")
756692
}
757693
}
758694

759695
for _, colI := range mapStringFloat64Cols {
760696
if row[colI] != nil {
761697
row[colI], err = conn.convertToMapStringFloat64(row[colI])
762698
eG.Capture(err)
763-
} else {
764-
g.Debug("empty mapstringfloat64 if value == nil")
765699
}
766700
}
767701

768702
for _, colI := range mapStringFloat32Cols {
769703
if row[colI] != nil {
770704
row[colI], err = conn.convertToMapStringFloat32(row[colI])
771705
eG.Capture(err)
772-
} else {
773-
g.Debug("empty mapstringfloat32 if value == nil")
774706
}
775707
}
776708

777709
for _, colI := range mapStringArrayStringCols {
778710
if row[colI] != nil {
779711
row[colI], err = conn.convertToMapStringArrayString(row[colI])
780712
eG.Capture(err)
781-
} else {
782-
g.Debug("empty mapstringarraystring if value == nil")
783713
}
784714
}
785715

786716
for _, colI := range mapInt32StringCols {
787717
if row[colI] != nil {
788718
row[colI], err = conn.convertToMapInt32String(row[colI])
789719
eG.Capture(err)
790-
} else {
791-
g.Debug("empty mapint32string if value == nil")
792720
}
793721
}
794722

795723
for _, colI := range mapInt64StringCols {
796724
if row[colI] != nil {
797725
row[colI], err = conn.convertToMapInt64String(row[colI])
798726
eG.Capture(err)
799-
} else {
800-
g.Debug("empty mapint64string if value == nil")
801727
}
802728
}
803729

0 commit comments

Comments
 (0)