Skip to content

Some optimizations for component detection#1384

Merged
grvillic merged 20 commits into
microsoft:mainfrom
narasamdya:dev/imnarasa/TryOptimize
May 2, 2025
Merged

Some optimizations for component detection#1384
grvillic merged 20 commits into
microsoft:mainfrom
narasamdya:dev/imnarasa/TryOptimize

Conversation

@narasamdya
Copy link
Copy Markdown
Contributor

@narasamdya narasamdya commented Apr 18, 2025

In a large 1JS repository, we have ~38% performance improvement (71s => 44s)

Notable gains are obtained from:

  1. Enabling parallelism in FileComponentDetector for Yarn.lock.
  2. Caching component ids to avoid repeated boxing due to string interpolations.

For (1), it is possible because OnFileFoundAsync for Yarn detector is thread safe. For (2), it is better to replace all set methods in properties to init, but the latter is not available for netstandard.

On large 1JS repository, the following show before and after for this command

Microsoft.ComponentDetection scan --SourceDirectory /workspaces/1JS --Timeout 600 --MaxDetectionThreads 128 --LogLevel Error --ScanType Register

on 1JS codespaces

Architecture:             x86_64
  CPU op-mode(s):         32-bit, 64-bit
  Address sizes:          48 bits physical, 48 bits virtual
  Byte Order:             Little Endian
CPU(s):                   16
  On-line CPU(s) list:    0-15
Vendor ID:                AuthenticAMD
  Model name:             AMD EPYC 7763 64-Core Processor

Before

real    1m11.729s
user    0m48.312s
sys     0m56.467s

After

real    0m44.163s
user    0m38.969s
sys     0m57.281s

Other perf. gain can be obtained by doing the following:

  • Separate directory traversal and processing files of workspace dependencies. Directory traversal only post the file/stream to an action block. This can boost ~5% perf.
  • Replace Newtonsoft.Json with System.Text.Json

@narasamdya narasamdya requested a review from a team as a code owner April 18, 2025 02:09
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2025

Codecov Report

Attention: Patch coverage is 93.90244% with 5 lines in your changes missing coverage. Please review.

Project coverage is 89.6%. Comparing base (43a7487) to head (3056e47).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...GraphTranslation/DefaultGraphTranslationService.cs 82.3% 0 Missing and 3 partials ⚠️
...ntracts/TypedComponent/DockerReferenceComponent.cs 0.0% 1 Missing ⚠️
...tection.Contracts/TypedComponent/VcpkgComponent.cs 92.3% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1384     +/-   ##
=======================================
- Coverage   89.6%   89.6%   -0.1%     
=======================================
  Files        401     401             
  Lines      31821   31811     -10     
  Branches    1965    1966      +1     
=======================================
- Hits       28539   28528     -11     
  Misses      2863    2863             
- Partials     419     420      +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@narasamdya narasamdya changed the title Small optimizations for component detection Some optimizations for component detection Apr 18, 2025
@narasamdya narasamdya changed the title Some optimizations for component detection Some optimizations for component detection (~38% perf boost) Apr 18, 2025
@narasamdya narasamdya changed the title Some optimizations for component detection (~38% perf boost) Some optimizations for component detection Apr 18, 2025
Comment thread src/Microsoft.ComponentDetection.Common/DependencyGraph/ComponentRecorder.cs Outdated
Comment thread src/Microsoft.ComponentDetection.Contracts/TypedComponent/TypedComponent.cs Outdated
Comment thread src/Microsoft.ComponentDetection.Contracts/TypedComponent/TypedComponent.cs Outdated
Copy link
Copy Markdown
Contributor

@jcfiorenzano jcfiorenzano left a comment

Choose a reason for hiding this comment

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

Waiting just for the bump of the yarn detector version.

@grvillic grvillic requested a review from jcfiorenzano May 1, 2025 19:59
@grvillic grvillic merged commit b6bac81 into microsoft:main May 2, 2025
22 of 23 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2025

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

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.

4 participants