Skip to content

Commit

Permalink
Remove panic from InternalDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Jul 3, 2023
1 parent 1dda134 commit ded2576
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 7 additions & 1 deletion pkg/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ func (d *Document) GarbageCollect(ticket *time.Ticket) int {
panic(err)
}
}
return d.doc.GarbageCollect(ticket)

n, err := d.doc.GarbageCollect(ticket)
if err != nil {
panic(err)
}

return n
}

// GarbageLen returns the count of removed elements.
Expand Down
13 changes: 5 additions & 8 deletions pkg/document/internal_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,17 @@ func (d *InternalDocument) ApplyChangePack(pack *change.Pack) error {
d.checkpoint = d.checkpoint.Forward(pack.Checkpoint)

if pack.MinSyncedTicket != nil {
d.GarbageCollect(pack.MinSyncedTicket)
if _, err := d.GarbageCollect(pack.MinSyncedTicket); err != nil {
return err
}
}

return nil
}

// GarbageCollect purge elements that were removed before the given time.
func (d *InternalDocument) GarbageCollect(ticket *time.Ticket) int {
n, err := d.root.GarbageCollect(ticket)
if err != nil {
panic(err)
}

return n
func (d *InternalDocument) GarbageCollect(ticket *time.Ticket) (int, error) {
return d.root.GarbageCollect(ticket)
}

// GarbageLen returns the count of removed elements.
Expand Down

1 comment on commit ded2576

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark

Benchmark suite Current: ded2576 Previous: 4ea648c Ratio
BenchmarkDocument/constructor_test 1516 ns/op 752 B/op 12 allocs/op 1545 ns/op 752 B/op 12 allocs/op 0.98
BenchmarkDocument/status_test 787.5 ns/op 720 B/op 10 allocs/op 1168 ns/op 720 B/op 10 allocs/op 0.67
BenchmarkDocument/equals_test 8482 ns/op 5072 B/op 85 allocs/op 8895 ns/op 5072 B/op 85 allocs/op 0.95
BenchmarkDocument/nested_update_test 25350 ns/op 11033 B/op 235 allocs/op 26694 ns/op 11033 B/op 235 allocs/op 0.95
BenchmarkDocument/delete_test 31806 ns/op 14163 B/op 310 allocs/op 34117 ns/op 14163 B/op 310 allocs/op 0.93
BenchmarkDocument/object_test 13500 ns/op 5792 B/op 97 allocs/op 11859 ns/op 5792 B/op 97 allocs/op 1.14
BenchmarkDocument/array_test 40421 ns/op 10889 B/op 251 allocs/op 42645 ns/op 10890 B/op 251 allocs/op 0.95
BenchmarkDocument/text_test 43448 ns/op 14057 B/op 456 allocs/op 45440 ns/op 14058 B/op 456 allocs/op 0.96
BenchmarkDocument/text_composition_test 45036 ns/op 17538 B/op 461 allocs/op 46261 ns/op 17538 B/op 461 allocs/op 0.97
BenchmarkDocument/rich_text_test 117804 ns/op 36006 B/op 1108 allocs/op 125421 ns/op 36016 B/op 1108 allocs/op 0.94
BenchmarkDocument/counter_test 22559 ns/op 9058 B/op 212 allocs/op 23699 ns/op 9057 B/op 212 allocs/op 0.95
BenchmarkDocument/text_edit_gc_100 4936837 ns/op 1552512 B/op 17148 allocs/op 4695110 ns/op 1552945 B/op 17150 allocs/op 1.05
BenchmarkDocument/text_edit_gc_1000 400885826 ns/op 136619192 B/op 210641 allocs/op 373729523 ns/op 136614104 B/op 210613 allocs/op 1.07
BenchmarkDocument/text_split_gc_100 5337886 ns/op 2217188 B/op 16576 allocs/op 5310214 ns/op 2217268 B/op 16575 allocs/op 1.01
BenchmarkDocument/text_split_gc_1000 451275612 ns/op 214877816 B/op 211512 allocs/op 456030707 ns/op 214829213 B/op 211274 allocs/op 0.99
BenchmarkDocument/text_delete_all_10000 21026411 ns/op 5904180 B/op 41120 allocs/op 20758627 ns/op 5903529 B/op 41120 allocs/op 1.01
BenchmarkDocument/text_delete_all_100000 261939173 ns/op 53839886 B/op 415970 allocs/op 277125629 ns/op 53842246 B/op 415985 allocs/op 0.95
BenchmarkDocument/text_100 366394 ns/op 117747 B/op 5064 allocs/op 386317 ns/op 117750 B/op 5064 allocs/op 0.95
BenchmarkDocument/text_1000 4031888 ns/op 1152338 B/op 50068 allocs/op 4349761 ns/op 1152368 B/op 50068 allocs/op 0.93
BenchmarkDocument/array_1000 2041764 ns/op 1102139 B/op 11854 allocs/op 2228492 ns/op 1102265 B/op 11855 allocs/op 0.92
BenchmarkDocument/array_10000 23661258 ns/op 9907663 B/op 120711 allocs/op 24525672 ns/op 9906337 B/op 120705 allocs/op 0.96
BenchmarkDocument/array_gc_100 216312 ns/op 97424 B/op 1227 allocs/op 223669 ns/op 97414 B/op 1226 allocs/op 0.97
BenchmarkDocument/array_gc_1000 2357756 ns/op 1169800 B/op 12890 allocs/op 2323875 ns/op 1169572 B/op 12889 allocs/op 1.01
BenchmarkDocument/counter_1000 351676 ns/op 197877 B/op 6490 allocs/op 330728 ns/op 197877 B/op 6490 allocs/op 1.06
BenchmarkDocument/counter_10000 3790654 ns/op 2164808 B/op 69497 allocs/op 3709166 ns/op 2164835 B/op 69497 allocs/op 1.02
BenchmarkDocument/object_1000 2322675 ns/op 1450712 B/op 9902 allocs/op 2176832 ns/op 1450706 B/op 9902 allocs/op 1.07
BenchmarkDocument/object_10000 27096058 ns/op 12368352 B/op 101204 allocs/op 25235487 ns/op 12366848 B/op 101199 allocs/op 1.07
BenchmarkRPC/client_to_server 659531110 ns/op 18442052 B/op 295022 allocs/op 531950074 ns/op 18897104 B/op 304291 allocs/op 1.24
BenchmarkRPC/client_to_client_via_server 1107919431 ns/op 30052488 B/op 458925 allocs/op 915461624 ns/op 34319028 B/op 560752 allocs/op 1.21
BenchmarkRPC/attach_large_document 1573334286 ns/op 2147038832 B/op 10095 allocs/op 1680941992 ns/op 2155547248 B/op 9927 allocs/op 0.94
BenchmarkRPC/adminCli_to_server 777948516 ns/op 20401080 B/op 322119 allocs/op 672776222 ns/op 20400180 B/op 322105 allocs/op 1.16
BenchmarkLocker 149.7 ns/op 16 B/op 1 allocs/op 141.3 ns/op 16 B/op 1 allocs/op 1.06
BenchmarkLockerParallel 192.3 ns/op 0 B/op 0 allocs/op 180.8 ns/op 0 B/op 0 allocs/op 1.06
BenchmarkLockerMoreKeys 377.7 ns/op 14 B/op 0 allocs/op 479.8 ns/op 13 B/op 0 allocs/op 0.79
BenchmarkSync/memory_sync_10_test 8871 ns/op 1340 B/op 39 allocs/op 8725 ns/op 1338 B/op 39 allocs/op 1.02
BenchmarkSync/memory_sync_100_test 74912 ns/op 8989 B/op 292 allocs/op 82836 ns/op 8713 B/op 275 allocs/op 0.90
BenchmarkSync/memory_sync_1000_test 704058 ns/op 82786 B/op 2638 allocs/op 790827 ns/op 81867 B/op 2581 allocs/op 0.89
BenchmarkSync/memory_sync_10000_test 7440572 ns/op 872133 B/op 28099 allocs/op 8059162 ns/op 869299 B/op 27283 allocs/op 0.92
BenchmarkTextEditing 31646808057 ns/op 8436264192 B/op 19835457 allocs/op 30303944825 ns/op 8435794576 B/op 19834770 allocs/op 1.04

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.