Skip to content
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

Cache scope priorities #1071

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/credo/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Credo.Application do
Credo.Service.SourceFileAST,
Credo.Service.SourceFileLines,
Credo.Service.SourceFileScopes,
Credo.Service.SourceFileScopePriorities,
Credo.Service.SourceFileSource
]

Expand Down
14 changes: 13 additions & 1 deletion lib/credo/check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ defmodule Credo.Check do
warning: 16
}

alias Credo.Service.SourceFileScopePriorities
alias Credo.Check
alias Credo.Check.Params
alias Credo.Code.Scope
Expand Down Expand Up @@ -759,7 +760,18 @@ defmodule Credo.Check do
end

defp priority_for(source_file, scope) do
scope_prio_map = Priority.scope_priorities(source_file)
# Caching scope priorities, because these have to be computed only once per file. This
# significantly speeds up the execution time when a large number of issues are generated.
scope_prio_map =
case SourceFileScopePriorities.get(source_file) do
{:ok, value} ->
value

:notfound ->
result = Priority.scope_priorities(source_file)
SourceFileScopePriorities.put(source_file, result)
result
end

scope_prio_map[scope] || 0
end
Expand Down
5 changes: 5 additions & 0 deletions lib/credo/service/source_file_scope_priorities.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Credo.Service.SourceFileScopePriorities do
@moduledoc false

use Credo.Service.ETSTableHelper
end
Loading