Skip to content

Refine mgmt emitter: replace isPrefix with getSharedSegmentCount in resource-detection#56185

Closed
live1206 wants to merge 1 commit intomainfrom
refine-mgmt-emitter-isprefix
Closed

Refine mgmt emitter: replace isPrefix with getSharedSegmentCount in resource-detection#56185
live1206 wants to merge 1 commit intomainfrom
refine-mgmt-emitter-isprefix

Conversation

@live1206
Copy link
Copy Markdown
Member

Description

Addresses feedback from #56180 (comment)

The isPrefix function in resource-detection.ts was being called alongside getSharedSegmentCount, leading to redundant path splitting operations. Since isPrefix internally calls getSharedSegmentCount, this resulted in the same paths being split multiple times.

Changes

  • utils.ts: Added getSegmentCount helper function. Updated isPrefix to use it.
  • resource-detection.ts: Replaced isPrefix + getSharedSegmentCount combo with direct getSharedSegmentCount + getSegmentCount calls, eliminating redundant splitting. Removed unused isPrefix import.

Testing

  • All 114 generator tests pass
  • All 39 emitter tests pass
  • Lint and prettier checks pass

…esource-detection

- Add getSegmentCount helper to utils.ts to avoid redundant path splitting
- Replace isPrefix + getSharedSegmentCount combo in resource-detection.ts
  with direct getSharedSegmentCount + getSegmentCount calls
- Update isPrefix itself to use getSegmentCount instead of inline splits
- Remove isPrefix import from resource-detection.ts (no longer needed)

This eliminates redundant string splitting operations where isPrefix
was called followed by getSharedSegmentCount on the same paths.

Addresses feedback from PR #56180 (discussion r2791991621).
Copilot AI review requested due to automatic review settings February 11, 2026 08:55
@github-actions github-actions bot added CodeGen Issues that relate to code generation Mgmt This issue is related to a management package. labels Feb 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refines the management-plane emitter’s legacy resource detection logic to reduce redundant path splitting when performing prefix/segment comparisons for parent/child resource matching.

Changes:

  • Added a getSegmentCount() utility and updated isPrefix() to use it.
  • Updated resource-detection.ts to use getSharedSegmentCount() + getSegmentCount() directly instead of combining isPrefix() with additional segment counting.
  • Removed the unused isPrefix import from resource-detection.ts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
eng/packages/http-client-csharp-mgmt/emitter/src/utils.ts Introduces getSegmentCount() and refactors isPrefix() to use segment counts rather than duplicating split/filter logic inline.
eng/packages/http-client-csharp-mgmt/emitter/src/resource-detection.ts Replaces isPrefix usage with explicit shared/segment-count checks to avoid redundant splitting during resource parent detection.

Comment on lines +190 to +198
const parentSegmentCount = getSegmentCount(existingParentPath);
const sharedCount = getSharedSegmentCount(
existingParentPath,
operationPath
);
if (
sharedCount === parentSegmentCount &&
sharedCount <= getSegmentCount(operationPath)
) {
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the for (const [existingKey] ...) loop, getSegmentCount(operationPath) is recomputed for every candidate check. Since operationPath doesn’t change within the loop, compute its segment count once before iterating (or at least once per processMethod call) and reuse it to avoid repeated split/filter work in this hot path.

Copilot uses AI. Check for mistakes.
@live1206 live1206 marked this pull request as draft February 11, 2026 08:59
Copy link
Copy Markdown
Member

@ArcturusZhang ArcturusZhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks fine, but if we really want to solve this on this end, the best way is to have a class describing request paths, which could keep tracking its own segments so that we do not have split a string all the time

@live1206 live1206 closed this Mar 10, 2026
@live1206 live1206 deleted the refine-mgmt-emitter-isprefix branch March 10, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CodeGen Issues that relate to code generation Mgmt This issue is related to a management package.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants