Optimize scripting-related cache creation and update
reduce number of cases when changes are reported from script dependencies provider, that causing rootsChanged event, in particular empty dependencies are filtered out now Should reduce IDEA startup delays.
This commit is contained in:
+29
-32
@@ -68,25 +68,22 @@ class KotlinScriptExternalImportsProviderImpl(
|
|||||||
var filesCount = 0
|
var filesCount = 0
|
||||||
var additionsCount = 0
|
var additionsCount = 0
|
||||||
val (res, time) = measureThreadTimeMillis {
|
val (res, time) = measureThreadTimeMillis {
|
||||||
val uncached = hashSetOf<String>()
|
|
||||||
files.mapNotNull { file ->
|
files.mapNotNull { file ->
|
||||||
filesCount += 1
|
filesCount += 1
|
||||||
val path = getFilePath(file)
|
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
||||||
if (isValidFile(file) && !cache.containsKey(path) && !uncached.contains(path)) {
|
if (scriptDef != null) {
|
||||||
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
val path = getFilePath(file)
|
||||||
if (scriptDef != null) {
|
if (isValidFile(file) && !cache.containsKey(path)) {
|
||||||
val deps = scriptDef.getDependenciesFor(file, project, null)
|
val deps = scriptDef.getDependenciesFor(file, project, null)
|
||||||
|
cache.put(path, deps)
|
||||||
if (deps != null) {
|
if (deps != null) {
|
||||||
log.info("[kts] cached deps for $path: ${deps.classpath.joinToString(File.pathSeparator)}")
|
log.info("[kts] cached deps for $path: ${deps.classpath.joinToString(File.pathSeparator)}")
|
||||||
|
additionsCount += 1
|
||||||
|
file
|
||||||
}
|
}
|
||||||
cache.put(path, deps)
|
else null
|
||||||
additionsCount += 1
|
|
||||||
file
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uncached.add(path)
|
|
||||||
null
|
|
||||||
}
|
}
|
||||||
|
else null
|
||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
}
|
}
|
||||||
@@ -104,20 +101,18 @@ class KotlinScriptExternalImportsProviderImpl(
|
|||||||
val (res, time) = measureThreadTimeMillis {
|
val (res, time) = measureThreadTimeMillis {
|
||||||
files.mapNotNull { file ->
|
files.mapNotNull { file ->
|
||||||
filesCount += 1
|
filesCount += 1
|
||||||
val path = getFilePath(file)
|
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
||||||
if (!isValidFile(file)) {
|
if (scriptDef != null) {
|
||||||
if (cache.remove(path) != null) {
|
val path = getFilePath(file)
|
||||||
log.debug("[kts] removed deps for file $path")
|
if (!isValidFile(file)) {
|
||||||
updatesCount += 1
|
if (cache.remove(path) != null) {
|
||||||
file
|
log.debug("[kts] removed deps for file $path")
|
||||||
} // cleared
|
updatesCount += 1
|
||||||
else {
|
file
|
||||||
null // unknown
|
} // cleared
|
||||||
|
else null // unknown
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
else {
|
|
||||||
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
|
||||||
if (scriptDef != null) {
|
|
||||||
val oldDeps = cache[path]
|
val oldDeps = cache[path]
|
||||||
val deps = scriptDef.getDependenciesFor(file, project, oldDeps)
|
val deps = scriptDef.getDependenciesFor(file, project, oldDeps)
|
||||||
when {
|
when {
|
||||||
@@ -126,21 +121,23 @@ class KotlinScriptExternalImportsProviderImpl(
|
|||||||
// changed or new
|
// changed or new
|
||||||
log.info("[kts] updated/new cached deps for $path: ${deps.classpath.joinToString(File.pathSeparator)}")
|
log.info("[kts] updated/new cached deps for $path: ${deps.classpath.joinToString(File.pathSeparator)}")
|
||||||
cache.put(path, deps)
|
cache.put(path, deps)
|
||||||
|
updatesCount += 1
|
||||||
|
file
|
||||||
}
|
}
|
||||||
deps != null -> {
|
deps != null -> {
|
||||||
// same as before
|
// same as before
|
||||||
|
null
|
||||||
}
|
}
|
||||||
else -> {
|
cache.remove(path) != null -> {
|
||||||
if (cache.remove(path) != null) {
|
log.debug("[kts] removed deps for $path")
|
||||||
log.debug("[kts] removed deps for $path")
|
updatesCount += 1
|
||||||
} // cleared
|
file
|
||||||
}
|
}
|
||||||
|
else -> null // unknown
|
||||||
}
|
}
|
||||||
updatesCount += 1
|
|
||||||
file
|
|
||||||
}
|
}
|
||||||
else null // not a script
|
|
||||||
}
|
}
|
||||||
|
else null // not a script
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updatesCount > 0) {
|
if (updatesCount > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user