Skip to content

internal/fwserver: Report semantic equality modification instead of comparing whole values - #1324

Open
samssh wants to merge 1 commit into
hashicorp:mainfrom
samssh:semantic-equality-modified-flag
Open

samssh wants to merge 1 commit into
hashicorp:mainfrom
samssh:semantic-equality-modified-flag

Conversation

@samssh

@samssh samssh commented Sep 3, 2026

Copy link
Copy Markdown

Related Issue

Fixes #1322 (partially — this PR covers site 3)

Description

ReadResource, CreateResource, UpdateResource and ReadDataSource decided
whether semantic equality had changed anything by deep-comparing the entire
returned value against the value they passed in:

if !semanticEqualityResp.NewData.TerraformValue.Equal(resp.NewState.Raw) {

For a resource with a large set attribute that comparison is O(n²) in the number
of set elements, and it runs on every one of those RPCs. In a CPU profile of a
real provider, a single call to this line accounted for 115s of a 181s profile.

SchemaSemanticEquality already knows whether it replaced a value — it is the
code doing the replacing — so it now reports that in the response and the four
call sites check the flag instead.

Four expectations in schema_semantic_equality_test.go gain Modified: true.
Those literals predate the field; in each of them the proposed value is "new"
and the expected new value is "prior", so the data genuinely changed and the
comparison being replaced reached the same conclusion. Nothing was weakened to
make a test pass.

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

No.

@samssh
samssh requested a review from a team as a code owner September 3, 2026 07:06
@hashicorp-cla-app

hashicorp-cla-app Bot commented Sep 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…omparing whole values

ReadResource, CreateResource, UpdateResource and ReadDataSource decided whether
semantic equality had changed anything by deep-comparing the entire returned
value against the value they passed in. For a resource with a large set
attribute that comparison is O(n^2) in the number of set elements, and it runs
on every one of those RPCs.

SchemaSemanticEquality already knows whether it replaced a value, so have it
report that in the response and drop the comparison. The four expectations
updated here predate the new field; in each of them the proposed value is
"new" and the expected new value is "prior", so the data did change and the
comparison they replace reached the same conclusion.
@samssh
samssh force-pushed the semantic-equality-modified-flag branch from 2429e93 to 22d39d2 Compare September 3, 2026 07:13
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.

Three O(n²) paths in set handling make plan and refresh unusable for large sets

1 participant