Skip to content

fix(skill): remove O(n^2) copies in computeSignature and unbounded file lock map - #3795

Merged
xzxiaoshan merged 3 commits into
agentscope-ai:mainfrom
xzxiaoshan:fix/skill-mirror-0c-perf-leaks
Oct 27, 2026
Merged

xzxiaoshan merged 3 commits into
agentscope-ai:mainfrom
xzxiaoshan:fix/skill-mirror-0c-perf-leaks

Conversation

@xzxiaoshan

@xzxiaoshan xzxiaoshan commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Two targeted fixes in the skill materialisation path:

  • DynamicSkillMiddleware.computeSignature copied the whole resource map on every key inside the hash loop (O(n²) per skill). It now enumerates keys once via getResourcePaths() and reads values with per-key getResource(); the hashed bytes — and therefore signature values — are unchanged (pinned by a golden-value regression test).
  • SkillBox.FILE_LOCKS was a static per-path lock map that accumulated one lock object per materialised path and was never cleaned. It is replaced by a fixed 256-stripe lock table (floorMod(pathHash, N)): same-path mutual exclusion is preserved, unrelated paths colliding on a stripe merely serialise, and lock memory no longer grows with path count.

Also includes (kept as separate commits):

Verified with mvn -T1C -pl agentscope-core -am test (2805 tests, 0 failures) and spotless:check.

…le lock map

- computeSignature: per-key getResource() instead of whole-map getResources()
  copies in the resource hash loop; signature bytes unchanged (golden-value test)
- SkillBox: fixed 256-stripe lock table replaces the per-path FILE_LOCKS map
  that accumulated one lock object per path and was never cleaned
…-perf-leaks

# Conflicts:
#	agentscope-core/src/test/java/io/agentscope/core/skill/DynamicSkillMiddlewareTest.java
…el build stalls

allow() piggybacks a sweep on the same windowMillis + cooldownMillis
threshold idle eviction uses, so a ~100ms stall on the first sleep let
that sweep evict the idle peer before the explicit evictIdlePeers()
call (observed under mvn -T1C). Rebalance the sleeps so every phase
keeps a 400ms margin against runner stalls; assertions unchanged.
@xzxiaoshan
xzxiaoshan merged commit de2dc8f into agentscope-ai:main Oct 27, 2026
5 checks passed
chickenlj added a commit that referenced this pull request Nov 13, 2026
…le lock map (#3795)

Source: de2dc8f
Candidate: 97476565ff0e691485ccc8bd9d1fb93170bca49a
Union-Of: execution53(468e2c2) + skill-standalone(97476565)
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