|
9 | 9 | "io" |
10 | 10 | "maps" |
11 | 11 | "math/big" |
| 12 | + "runtime" |
12 | 13 | "slices" |
13 | 14 | "strings" |
14 | 15 | "sync" |
@@ -445,14 +446,14 @@ func (w *workflowRegistry) generateReconciliationEvents( |
445 | 446 | ) ([]*reconciliationEvent, error) { |
446 | 447 | var events []*reconciliationEvent |
447 | 448 | localHead := toLocalHead(head) |
448 | | - // workflowMetadataMap is only used for lookups; disregard when reading the state machine. |
449 | | - workflowMetadataMap := make(map[string]WorkflowMetadataView) |
| 449 | + // workflowMetadataIDs is a set of workflow IDs present in this tick's metadata |
| 450 | + workflowMetadataIDs := make(map[string]struct{}, len(workflowMetadata)) |
450 | 451 | for _, wfMeta := range workflowMetadata { |
451 | | - workflowMetadataMap[wfMeta.WorkflowID.Hex()] = wfMeta |
| 452 | + workflowMetadataIDs[wfMeta.WorkflowID.Hex()] = struct{}{} |
452 | 453 | } |
453 | 454 |
|
454 | | - // Keep track of which of the engines in the engineRegistry have been touched |
455 | | - workflowsSeen := map[string]bool{} |
| 455 | + // Keep track of which of the engines in the engineRegistry have been touched. |
| 456 | + workflowsSeen := make(map[string]bool, len(workflowMetadata)) |
456 | 457 | for _, wfMeta := range workflowMetadata { |
457 | 458 | id := wfMeta.WorkflowID.Hex() |
458 | 459 | engineFound := w.engineRegistry.Contains(wfMeta.WorkflowID) |
@@ -596,7 +597,7 @@ func (w *workflowRegistry) generateReconciliationEvents( |
596 | 597 | // the workflow no longer exists in this source's metadata |
597 | 598 | for id, event := range pendingEvents { |
598 | 599 | if event.Name == WorkflowActivated { |
599 | | - if _, ok := workflowMetadataMap[event.Data.(WorkflowActivatedEvent).WorkflowID.Hex()]; !ok { |
| 600 | + if _, ok := workflowMetadataIDs[event.Data.(WorkflowActivatedEvent).WorkflowID.Hex()]; !ok { |
600 | 601 | delete(pendingEvents, id) |
601 | 602 | } |
602 | 603 | } |
@@ -818,6 +819,12 @@ func (w *workflowRegistry) syncUsingReconciliationStrategy(ctx context.Context) |
818 | 819 | } |
819 | 820 | wg.Wait() |
820 | 821 |
|
| 822 | + // prompt the GC to reclaim transient allocations from event handling |
| 823 | + // that would otherwise be delayed because the dominant CGo/wasmtime memory is invisible to the Go GC |
| 824 | + if dispatched > 0 { |
| 825 | + runtime.GC() |
| 826 | + } |
| 827 | + |
821 | 828 | batchDuration := time.Since(batchStart) |
822 | 829 | w.metrics.recordReconcileBatch(ctx, sourceName, dispatched, batchDuration) |
823 | 830 | if backoffCount > 0 { |
|
0 commit comments