Skip to content

Commit

Permalink
lint(track_config): optimize concept cycle checking slightly (#489)
Browse files Browse the repository at this point in the history
We were concatenating a sequence with a one-item sequence, but it's
better to use the `&` overload that appends one item [1][2]. The
Nim compiler deliberately doesn't optimize the former into the latter.

The concept cycle checking is a hot spot on tracks with a larger number
of Concept Exercises. For example, with the csharp track, about a third
of the `configlet lint` execution time was spent in `checkForCycle`.
This commit removes some unnecessary allocations within that hot spot,
and thereby produces a small (but consistent) `configlet lint` speedup
of 3-5% on such tracks.

[1] https://github.com/nim-lang/Nim/blob/9084d9bc02bc/lib/system.nim#L1672-L1686
[2] https://github.com/nim-lang/Nim/blob/9084d9bc02bc/lib/system.nim#L1688-L1701
  • Loading branch information
ee7 authored Jan 6, 2022
1 parent dc7e82c commit fd78c1b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lint/track_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ proc checkForCycle(prerequisitesByConcept: Table[string, seq[string]];
if hadCycle:
return

let updatedPrereqPath = prereqPath & @[currentConcept]
let updatedPrereqPath = prereqPath & currentConcept
if currentConcept in prereqPath:
var formattedCycle = &"{q updatedPrereqPath[0]} depends on {q updatedPrereqPath[1]}"
for i in 1..prereqPath.high:
Expand Down

0 comments on commit fd78c1b

Please sign in to comment.