MaibornWolff / metric-gardener

BSD 3-Clause "New" or "Revised" License
6 stars 0 forks source link

Performance Optimizations for coupling metrics (--parseDependencies) #13

Open ce-bo opened 10 months ago

ce-bo commented 10 months ago

some points about possible improvements:

During Dependency Parsing:

BridgeAR commented 9 months ago

Without benchmarking, I also expect the data structures being used as being highly problematic.

Right now, multiple data structures are copied each time an entry is added.

https://github.com/MaibornWolff/metric-gardener/blob/f5e498fec945f58d07565c813630bb57ca366a62/src/parser/metrics/coupling/Coupling.ts#L41-L44

Should be e.g.:

for (const [key, name] of this.namespaceCollector.getNamespaces(parseFile)) {
  namespaces.add(key, name)
}

https://github.com/MaibornWolff/metric-gardener/blob/f5e498fec945f58d07565c813630bb57ca366a62/src/parser/metrics/coupling/Coupling.ts#L64C13-L64C68

Should be

// Note: that limits the candidates to ~100000
usagesCandidates.push(...candidates)

Concat is always copying an array and should almost never be used. Using the spread operator as above is also going to copy everything. That requires a lot of CPU cycles in addition to triggering the garbage collector frequently.

This is likely in more places a problem.