Skip to content

Conversation

rsdmike
Copy link
Member

@rsdmike rsdmike commented Aug 25, 2025

No description provided.

@Copilot Copilot AI review requested due to automatic review settings August 25, 2025 20:07
Copilot

This comment was marked as outdated.

Copilot

This comment was marked as outdated.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes network operations by implementing conditional deadline setting for read/write operations to reduce syscall overhead. The optimization only updates TCP connection deadlines when necessary, rather than on every operation.

  • Adds read/write timeout constants and conditional deadline setting logic
  • Implements deadline tracking with mutex protection to avoid unnecessary syscalls
  • Resets deadline tracking state when connections are closed

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/wsman/client/wsman_tcp.go Implements conditional deadline setting methods and integrates them into Send/Receive operations
pkg/wsman/client/wsman.go Adds deadline tracking fields to the Target struct

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

now := time.Now()
// Only set deadline if it's been more than half the timeout period since last set
// or if it's never been set (zero value)
const deadlineRefreshInterval = defaultReadTimeout / 2
Copy link
Preview

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

The magic number division by 2 should be extracted to a named constant to improve code clarity and maintainability.

Suggested change
const deadlineRefreshInterval = defaultReadTimeout / 2
const deadlineRefreshInterval = defaultReadTimeout / deadlineRefreshDivisor

Copilot uses AI. Check for mistakes.

now := time.Now()
// Only set deadline if it's been more than half the timeout period since last set
// or if it's never been set (zero value)
const deadlineRefreshInterval = defaultWriteTimeout / 2
Copy link
Preview

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

This duplicates the same magic number division by 2 from the read method. Consider extracting a shared constant like deadlineRefreshRatio = 0.5 to avoid duplication.

Suggested change
const deadlineRefreshInterval = defaultWriteTimeout / 2
const deadlineRefreshInterval = time.Duration(float64(defaultWriteTimeout) * deadlineRefreshRatio)

Copilot uses AI. Check for mistakes.

}

// setReadDeadlineIfNeeded sets read deadline only when needed to reduce syscall overhead
func (t *Target) setReadDeadlineIfNeeded() error {
Copy link
Preview

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

The deadline optimization could create a race condition where multiple goroutines might call Send/Receive simultaneously. Consider if the current mutex protection is sufficient for all concurrent access patterns.

Copilot uses AI. Check for mistakes.

// or if it's never been set (zero value)
const deadlineRefreshInterval = defaultReadTimeout / 2

if t.lastReadDeadlineSet.IsZero() || now.Sub(t.lastReadDeadlineSet) > deadlineRefreshInterval {
Copy link
Preview

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

Calling time.Now() on every Send/Receive operation may impact performance. Consider caching the current time or using a less precise but faster time source for the deadline refresh logic.

Copilot uses AI. Check for mistakes.

@rsdmike rsdmike closed this Aug 25, 2025
@rsdmike rsdmike deleted the perf branch August 25, 2025 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants