Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
65cece59
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
65cece59
编写于
9月 27, 2019
作者:
S
Sam Harwell
提交者:
GitHub
9月 27, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34762 from Therzok/allocation-diagnostics
Reduce allocations in DiagnosticIncrementalAnalyzer
上级
148f684c
8acfadf8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
49 addition
and
24 deletion
+49
-24
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs
...ostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs
+34
-22
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs
...ble/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs
+15
-2
未找到文件。
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs
浏览文件 @
65cece59
...
...
@@ -2,6 +2,7 @@
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
...
...
@@ -57,14 +58,12 @@ public StateSet(string language, DiagnosticAnalyzer analyzer, string errorSource
public
DiagnosticAnalyzer
Analyzer
=>
_analyzer
;
public
VersionStamp
AnalyzerVersion
=>
_analyzerVersion
;
[
PerformanceSensitive
(
"https://github.com/dotnet/roslyn/issues/34761"
,
AllowCaptures
=
false
,
AllowGenericEnumeration
=
false
)]
public
bool
ContainsAnyDocumentOrProjectDiagnostics
(
ProjectId
projectId
)
{
foreach
(
var
state
in
GetActiveFileStates
(
projectId
))
if
(
ContainsAnyDocumentDiagnostics
(
_activeFileStates
,
projectId
))
{
if
(!
state
.
IsEmpty
)
{
return
true
;
}
return
true
;
}
if
(!
_projectStates
.
TryGetValue
(
projectId
,
out
var
projectState
))
...
...
@@ -73,6 +72,24 @@ public bool ContainsAnyDocumentOrProjectDiagnostics(ProjectId projectId)
}
return
!
projectState
.
IsEmpty
();
static
bool
ContainsAnyDocumentDiagnostics
(
ConcurrentDictionary
<
DocumentId
,
ActiveFileState
>
activeFileStates
,
ProjectId
projectId
)
{
foreach
(
var
kvp
in
activeFileStates
)
{
var
documentId
=
kvp
.
Key
;
if
(
documentId
.
ProjectId
==
projectId
)
{
var
state
=
kvp
.
Value
;
if
(!
state
.
IsEmpty
)
{
return
true
;
}
}
}
return
false
;
}
}
public
IEnumerable
<
ProjectId
>
GetProjectsWithDiagnostics
()
...
...
@@ -103,29 +120,24 @@ public IEnumerable<ProjectId> GetProjectsWithDiagnostics()
.
Select
(
kv
=>
kv
.
Key
)));
}
public
IEnumerable
<
DocumentId
>
GetDocumentsWithDiagnostics
(
ProjectId
projectId
)
[
PerformanceSensitive
(
"https://github.com/dotnet/roslyn/issues/34761"
,
AllowCaptures
=
false
,
AllowGenericEnumeration
=
false
)]
public
void
CollectDocumentsWithDiagnostics
(
ProjectId
projectId
,
HashSet
<
DocumentId
>
set
)
{
HashSet
<
DocumentId
>
set
=
null
;
foreach
(
var
state
in
GetActiveFileStates
(
projectId
))
Debug
.
Assert
(
set
!=
null
);
// Collect active documents with diagnostics
foreach
(
var
kvp
in
_activeFileStates
)
{
set
??=
new
HashSet
<
DocumentId
>();
set
.
Add
(
state
.
DocumentId
);
if
(
kvp
.
Key
.
ProjectId
==
projectId
)
{
set
.
Add
(
kvp
.
Value
.
DocumentId
);
}
}
if
(
!
_projectStates
.
TryGetValue
(
projectId
,
out
var
projectState
)
||
projectState
.
IsEmpty
())
if
(
_projectStates
.
TryGetValue
(
projectId
,
out
var
projectState
)
&&
!
projectState
.
IsEmpty
())
{
return
set
??
SpecializedCollections
.
EmptyEnumerable
<
DocumentId
>(
);
set
.
UnionWith
(
projectState
.
GetDocumentsWithDiagnostics
()
);
}
set
??=
new
HashSet
<
DocumentId
>();
set
.
UnionWith
(
projectState
.
GetDocumentsWithDiagnostics
());
return
set
;
}
private
IEnumerable
<
ActiveFileState
>
GetActiveFileStates
(
ProjectId
projectId
)
{
return
_activeFileStates
.
Where
(
kv
=>
kv
.
Key
.
ProjectId
==
projectId
).
Select
(
kv
=>
kv
.
Value
);
}
public
bool
IsActiveFile
(
DocumentId
documentId
)
...
...
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs
浏览文件 @
65cece59
...
...
@@ -9,6 +9,7 @@
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.Diagnostics.Log
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Shared.Options
;
using
Microsoft.CodeAnalysis.Simplification
;
using
Microsoft.CodeAnalysis.SolutionCrawler
;
...
...
@@ -115,14 +116,20 @@ public void Shutdown()
Owner
.
RaiseBulkDiagnosticsUpdated
(
raiseEvents
=>
{
var
handleActiveFile
=
true
;
var
documentSet
=
PooledHashSet
<
DocumentId
>.
GetInstance
();
foreach
(
var
stateSet
in
stateSets
)
{
var
projectIds
=
stateSet
.
GetProjectsWithDiagnostics
();
foreach
(
var
projectId
in
projectIds
)
{
RaiseProjectDiagnosticsRemoved
(
stateSet
,
projectId
,
stateSet
.
GetDocumentsWithDiagnostics
(
projectId
),
handleActiveFile
,
raiseEvents
);
stateSet
.
CollectDocumentsWithDiagnostics
(
projectId
,
documentSet
);
RaiseProjectDiagnosticsRemoved
(
stateSet
,
projectId
,
documentSet
,
handleActiveFile
,
raiseEvents
);
documentSet
.
Clear
();
}
}
documentSet
.
Free
();
});
}
...
...
@@ -131,6 +138,8 @@ private void ClearAllDiagnostics(ImmutableArray<StateSet> stateSets, ProjectId p
Owner
.
RaiseBulkDiagnosticsUpdated
(
raiseEvents
=>
{
var
handleActiveFile
=
true
;
var
documentSet
=
PooledHashSet
<
DocumentId
>.
GetInstance
();
foreach
(
var
stateSet
in
stateSets
)
{
// PERF: don't fire events for ones that we dont have any diagnostics on
...
...
@@ -139,8 +148,12 @@ private void ClearAllDiagnostics(ImmutableArray<StateSet> stateSets, ProjectId p
continue
;
}
RaiseProjectDiagnosticsRemoved
(
stateSet
,
projectId
,
stateSet
.
GetDocumentsWithDiagnostics
(
projectId
),
handleActiveFile
,
raiseEvents
);
stateSet
.
CollectDocumentsWithDiagnostics
(
projectId
,
documentSet
);
RaiseProjectDiagnosticsRemoved
(
stateSet
,
projectId
,
documentSet
,
handleActiveFile
,
raiseEvents
);
documentSet
.
Clear
();
}
documentSet
.
Free
();
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录