-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(npm): Remove unused parallelization constructs #9316
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,6 @@ package org.ossreviewtoolkit.plugins.packagemanagers.node | |
import java.io.File | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
import kotlinx.coroutines.Deferred | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.withContext | ||
|
||
import org.apache.logging.log4j.kotlin.logger | ||
|
||
import org.ossreviewtoolkit.analyzer.AbstractPackageManagerFactory | ||
|
@@ -120,7 +115,7 @@ open class Npm( | |
|
||
private val graphBuilder by lazy { DependencyGraphBuilder(NpmDependencyHandler(this)) } | ||
|
||
private val npmViewCache = ConcurrentHashMap<String, Deferred<PackageJson>>() | ||
private val npmViewCache = mutableMapOf<String, PackageJson>() | ||
|
||
protected open fun hasLockfile(projectDir: File) = NodePackageManager.NPM.hasLockfile(projectDir) | ||
|
||
|
@@ -249,11 +244,7 @@ open class Npm( | |
* Construct a [Package] by parsing its _package.json_ file and - if applicable - querying additional | ||
* content via the `npm view` command. The result is a [Pair] with the raw identifier and the new package. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit message nit: "...would have searched..." |
||
*/ | ||
internal suspend fun parsePackage(workingDir: File, packageJsonFile: File): Package { | ||
val packageDir = packageJsonFile.parentFile | ||
|
||
logger.debug { "Found a 'package.json' file in '$packageDir'." } | ||
|
||
internal fun parsePackage(workingDir: File, packageJsonFile: File): Package { | ||
val packageJson = parsePackageJson(packageJsonFile) | ||
|
||
// The "name" and "version" fields are only required if the package is going to be published, otherwise they are | ||
|
@@ -289,7 +280,7 @@ open class Npm( | |
|
||
if (hasIncompleteData) { | ||
runCatching { | ||
getRemotePackageDetailsAsync(workingDir, "$rawName@$version").await() | ||
getRemotePackageDetails(workingDir, "$rawName@$version") | ||
}.onSuccess { details -> | ||
if (description.isEmpty()) description = details.description.orEmpty() | ||
if (homepageUrl.isEmpty()) homepageUrl = details.homepage.orEmpty() | ||
|
@@ -342,20 +333,12 @@ open class Npm( | |
return module | ||
} | ||
|
||
private suspend fun getRemotePackageDetailsAsync(workingDir: File, packageName: String): Deferred<PackageJson> = | ||
withContext(Dispatchers.IO) { | ||
npmViewCache.getOrPut(packageName) { | ||
async { | ||
getRemotePackageDetails(workingDir, packageName) | ||
} | ||
} | ||
protected open fun getRemotePackageDetails(workingDir: File, packageName: String): PackageJson = | ||
npmViewCache.getOrPut(packageName) { | ||
val process = run(workingDir, "info", "--json", packageName) | ||
parsePackageJson(process.stdout) | ||
} | ||
|
||
protected open fun getRemotePackageDetails(workingDir: File, packageName: String): PackageJson { | ||
val process = run(workingDir, "info", "--json", packageName) | ||
return parsePackageJson(process.stdout) | ||
} | ||
|
||
/** Cache for submodules identified by its moduleDir absolutePath */ | ||
private val submodulesCache = ConcurrentHashMap<String, Set<File>>() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit message:
Nit: "...strictly sequentially."
So, if I understand correctly, the whole fiddling with
async
had no real effect, since only a single package was processed, and theparsePackage
function is only called sequentially? Maybe make this a bit more explicit in the commit message?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, I made the observation when running the fun tests, so not a single package but multiple package were involved. (A single package cannot be processed in parallel, so I guess this is a mis-understanding)
I in fact verified that
getRemotePackageDetails()
executes only sequentally. But,parsePackage()
is the only caller of that one, so I guess the same applied toparsePackage()
.What change to the commit message do you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand, there are multiple aspects:
withContext
construct ingetRemotePackageDetailsAsync
is only exited after all coroutines started within it are finished. Therefore, theasync
invocations are useless, since the function waits until the asynchronous processing is complete.parsePackage
is invoked sequentially for each package and waits for the result. So, even if asynchronous processing worked, it would not help here.Do you agree with this?
Regarding the commit message, it is probably not necessary to describe this in detail. So, your text is probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense to me.