Skip to content

perf: replace O(n) duplicate scan in calculate_sla with indexed lookup #44

Description

@Icahbod

calculate_sla iterates the entire history vector on every invocation to find an existing entry for the supplied outage_id. As HISTORY_KEY grows toward MAX_HISTORY_SIZE (1000) and beyond under the configurable retention limit, this linear scan degrades the hot path of the contract, blowing gas costs on every call and amounting to O(n^2) work over the contract lifetime. Maintain a parallel Map<Symbol, u32> (suggested key LAST_BY_OUTAGE) keyed by outage ID and updated inside the same storage write batch so duplicate detection becomes O(1). Add a regression test that submits N+1 distinct outage IDs and asserts gas usage of the duplicate-detection path is flat, not linear in N.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official Campaigngas

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions