@@ -522,13 +522,30 @@ func (b *Batch) importValueData() error {
522
522
523
523
// trim out null values from ids and values.
524
524
nullIndices := b .nullIndices [field ]
525
+ // TODO(jaffee) I think this may be very inefficient. It looks
526
+ // like we're copying the `ids` and `values` slices over
527
+ // themselves (an O(n) operation) for each nullIndex so this
528
+ // is effectively O(n^2). What we could do is iterate through
529
+ // ids and values each once, while simultaneously iterating
530
+ // through nullindices and keeping track of how many
531
+ // nullIndices we've passed, and so how far back we need to
532
+ // copy each item.
533
+ //
534
+ // It was a couple weeks ago that I wrote this code, and I
535
+ // vaugely remember thinking about this, so I may just be
536
+ // missing something now. We should benchmark on what should
537
+ // be a bad case (an int field which is mostly null), and see
538
+ // if the improved implementation helps a lot.
525
539
for i , nullIndex := range nullIndices {
526
540
nullIndex -= uint64 (i ) // offset the index by the number of items removed so far
527
541
ids = append (ids [:nullIndex ], ids [nullIndex + 1 :]... )
528
542
values = append (values [:nullIndex ], values [nullIndex + 1 :]... )
529
543
}
530
544
531
545
// now do imports by shard
546
+ if len (ids ) == 0 {
547
+ continue // TODO test this "all nil" case
548
+ }
532
549
curShard := ids [0 ] / shardWidth
533
550
startIdx := 0
534
551
for i := 1 ; i <= len (ids ); i ++ {
0 commit comments