Skip to content

Commit d44b26c

Browse files
authored
Merge pull request #218 from DataObjects-NET/master-small-improvements
A bunch of small changes
2 parents 421f57e + eabe50c commit d44b26c

File tree

9 files changed

+127
-3733
lines changed

9 files changed

+127
-3733
lines changed

Orm/Xtensive.Orm.Tests/Xtensive.Orm.Tests.csproj

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
44
<AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
@@ -29,21 +29,9 @@
2929
<ProjectReference Include="..\Xtensive.Orm\Xtensive.Orm.csproj" />
3030
</ItemGroup>
3131
<ItemGroup>
32-
<None Update="Model\InterfaceAssociationsModelGenerator.tt">
33-
<Generator>TextTemplatingFileGenerator</Generator>
34-
</None>
3532
<None Update="Northwind.xml">
3633
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3734
</None>
38-
<None Update="Upgrade\HugeModelUpgrade\Models\ModelWithMappedTypes.tt">
39-
<Generator>TextTemplatingFileGenerator</Generator>
40-
</None>
41-
<None Update="Upgrade\HugeModelUpgrade\Models\RegularModel.tt">
42-
<Generator>TextTemplatingFileGenerator</Generator>
43-
</None>
44-
<None Update="Upgrade\HugeModelUpgrade\Models\TwoPartsModel.tt">
45-
<Generator>TextTemplatingFileGenerator</Generator>
46-
</None>
4735
<None Update="Chinook.xml">
4836
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4937
</None>

Orm/Xtensive.Orm/Orm/Providers/CommandProcessing/BatchingCommandProcessor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Xtensive.Orm.Providers
1515
internal sealed class BatchingCommandProcessor : CommandProcessor, ISqlTaskProcessor
1616
{
1717
private readonly int batchSize;
18-
private Queue<SqlTask> tasks = new Queue<SqlTask>();
18+
private Queue<SqlTask> tasks;
1919

2020
void ISqlTaskProcessor.ProcessTask(SqlLoadTask task, CommandProcessorContext context)
2121
{
@@ -290,7 +290,7 @@ private void PutTasksForExecution(CommandProcessorContext context)
290290
}
291291
else {
292292
context.ProcessingTasks = tasks;
293-
tasks = new Queue<SqlTask>();
293+
tasks = new Queue<SqlTask>(batchSize);
294294
}
295295
}
296296

@@ -328,6 +328,7 @@ public BatchingCommandProcessor(CommandFactory factory, int batchSize, int maxQu
328328
{
329329
ArgumentValidator.EnsureArgumentIsGreaterThan(batchSize, 1, nameof(batchSize));
330330
this.batchSize = batchSize;
331+
this.tasks = new Queue<SqlTask>(batchSize);
331332
}
332333
}
333334
}

Orm/Xtensive.Orm/Orm/Providers/CommandProcessing/SimpleCommandProcessor.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ namespace Xtensive.Orm.Providers
1414
{
1515
internal sealed class SimpleCommandProcessor : CommandProcessor, ISqlTaskProcessor
1616
{
17-
private readonly Queue<SqlTask> tasks;
17+
// equals to default batch size from SessionConfiguration
18+
// hard to choose particular value so let it be some known number :)
19+
private const int DefaultTaskQueueCapacity = 25;
20+
21+
private Queue<SqlTask> tasks = new(DefaultTaskQueueCapacity);
1822

1923
void ISqlTaskProcessor.ProcessTask(SqlLoadTask task, CommandProcessorContext context)
2024
{
@@ -51,8 +55,8 @@ void ISqlTaskProcessor.ProcessTask(SqlPersistTask task, CommandProcessorContext
5155

5256
public override void ExecuteTasks(CommandProcessorContext context)
5357
{
54-
context.ProcessingTasks = new Queue<SqlTask>(tasks);
55-
tasks.Clear();
58+
context.ProcessingTasks = tasks;
59+
tasks = new Queue<SqlTask>(DefaultTaskQueueCapacity);
5660

5761
while (context.ProcessingTasks.Count > 0) {
5862
AllocateCommand(context);
@@ -79,8 +83,8 @@ public override void ExecuteTasks(CommandProcessorContext context)
7983

8084
public override async Task ExecuteTasksAsync(CommandProcessorContext context, CancellationToken token)
8185
{
82-
context.ProcessingTasks = new Queue<SqlTask>(tasks);
83-
tasks.Clear();
86+
context.ProcessingTasks = tasks;
87+
tasks = new Queue<SqlTask>(DefaultTaskQueueCapacity);
8488

8589
while (context.ProcessingTasks.Count > 0) {
8690
AllocateCommand(context);
@@ -152,7 +156,6 @@ private void ValidateCommandParameters(CommandPart commandPart)
152156
public SimpleCommandProcessor(CommandFactory factory, int maxQueryParameterCount)
153157
: base(factory, maxQueryParameterCount)
154158
{
155-
tasks = new Queue<SqlTask>();
156159
}
157160
}
158161
}

Orm/Xtensive.Orm/Orm/QueryableExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static IQueryable<TSource> Tag<TSource>(this IQueryable<TSource> source,
4242

4343
var providerType = source.Provider.GetType();
4444
if (providerType != WellKnownOrmTypes.QueryProvider) {
45-
var errorMessage = Strings.ExTakeDoesNotSupportQueryProviderOfTypeX;
45+
var errorMessage = Strings.ExTagDoesNotSupportQueryProviderOfTypeX;
4646
throw new NotSupportedException(string.Format(errorMessage, providerType));
4747
}
4848

@@ -66,7 +66,7 @@ public static IQueryable Tag(this IQueryable source, string tag)
6666

6767
var providerType = source.Provider.GetType();
6868
if (providerType != WellKnownOrmTypes.QueryProvider) {
69-
var errorMessage = Strings.ExTakeDoesNotSupportQueryProviderOfTypeX;
69+
var errorMessage = Strings.ExTagDoesNotSupportQueryProviderOfTypeX;
7070
throw new NotSupportedException(string.Format(errorMessage, providerType));
7171
}
7272

Orm/Xtensive.Orm/Orm/Rse/ColumnCollection.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,16 @@ public ColumnCollection Alias(string alias)
122122
/// Initializes a new instance of this class.
123123
/// </summary>
124124
/// <param name="columns">Collection of items to add.</param>
125+
/// <remarks>
126+
/// <paramref name="columns"/> is used to initialize inner field directly
127+
/// to save time on avoiding collection copy. If you pass an <see cref="IReadOnlyList{Column}"/>
128+
/// implementor that, in fact, can be changed, make sure the passed collection doesn't change afterwards.
129+
/// Ideally, use arrays instead of <see cref="List{T}"/> or similar collections.
130+
/// Changing the passed collection afterwards will lead to unpredictable results.
131+
/// </remarks>
125132
public ColumnCollection(IReadOnlyList<Column> columns)
126133
{
134+
//!!! Direct initialization by parameter is unsafe performance optimization: See remarks in ctor summary!
127135
this.columns = columns;
128136
var count = this.columns.Count;
129137
nameIndex = new Dictionary<string, int>(count);

Orm/Xtensive.Orm/Orm/Rse/ColumnGroupCollection.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@ public static ColumnGroupCollection Empty {
5555
/// Initializes a new instance of this class.
5656
/// </summary>
5757
/// <param name="items">The collection items.</param>
58+
/// <remarks>
59+
/// <paramref name="items"/> is used to initialize inner field directly
60+
/// to save time on avoiding collection copy. If you pass an <see cref="IReadOnlyList{ColumnGroup}"/>
61+
/// implementor that, in fact, can be changed, make sure the passed collection doesn't change afterwards.
62+
/// Ideally, use arrays instead of <see cref="List{T}"/> or similar collections.
63+
/// Changing the passed collection afterwards will lead to unpredictable results.
64+
/// </remarks>
5865
public ColumnGroupCollection(IReadOnlyList<ColumnGroup> items)
5966
{
67+
//!!! Direct initialization by parameter is unsafe performance optimization: See remark in ctor summary!
6068
this.items = items;
6169
}
6270
}

0 commit comments

Comments
 (0)