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.
calculate_slaiterates the entire history vector on every invocation to find an existing entry for the suppliedoutage_id. AsHISTORY_KEYgrows towardMAX_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 toO(n^2)work over the contract lifetime. Maintain a parallelMap<Symbol, u32>(suggested keyLAST_BY_OUTAGE) keyed by outage ID and updated inside the same storage write batch so duplicate detection becomesO(1). Add a regression test that submitsN+1distinct outage IDs and asserts gas usage of the duplicate-detection path is flat, not linear inN.