Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use reflect to test equity of message headers #1814

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Aden-Q
Copy link

@Aden-Q Aden-Q commented Mar 8, 2025

This patch uses reflection to test equality of message headers. This apporach is more efficient in the case when:

  • Both m.Header and msg.Header are non-nil
  • m.Header and msg.Header share the same underlying object, so the equality can be caught before testing the content of the map, compared to the original approach. For reference, map reflect implementation in go source code:
	case Map:
		if v1.IsNil() != v2.IsNil() {
			return false
		}
		if v1.Len() != v2.Len() {
			return false
		}
		if v1.UnsafePointer() == v2.UnsafePointer() {
			return true
		}
		iter := v1.MapRange()
		for iter.Next() {
			val1 := iter.Value()
			val2 := v2.MapIndex(iter.Key())
			if !val1.IsValid() || !val2.IsValid() || !deepValueEqual(val1, val2, visited) {
				return false
			}
		}
		return true

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.

1 participant