Skip to content

Conversation

@SergeiPavlov
Copy link
Collaborator

@SergeiPavlov SergeiPavlov commented Dec 15, 2025

Also:

  • Get rid of unused ConvertingEnumerator, ConvertingEnumerable
  • Optimize StructureExpression, StructureFieldExpression
  • Optimize IndexInfo: put array into it instead of Lists
  • Optimize EnsureNotLocked() - don't pollute CPU cache by throw statement

@SergeiPavlov SergeiPavlov changed the base branch from master to master-servicetitan December 15, 2025 19:22
@SergeiPavlov SergeiPavlov changed the title Type registry Optimize TypeRegistry Dec 15, 2025
@SergeiPavlov SergeiPavlov merged commit 6fedf5a into master-servicetitan Dec 16, 2025
6 checks passed
@SergeiPavlov SergeiPavlov deleted the TypeRegistry branch December 16, 2025 08:46
Comment on lines +28 to +31
public void EnsureNotLocked()
{

/// <inheritdoc/>
public bool IsLocked { [DebuggerStepThrough] get; private set; }

/// <summary>
/// Ensures the object is not locked (see <see cref="ILockable.Lock()"/>) yet.
/// </summary>
/// <exception cref="InstanceIsLockedException">The instance is locked.</exception>
public void EnsureNotLocked()
{
if (IsLocked) {
throw new InstanceIsLockedException(Strings.ExInstanceIsLocked);
}
if (IsLocked) {
ThrowInstanceIsLockedException();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like necessary change. The method is small enough and encapsulates Exception throwing inside. Most probably there is no sense of splitting it into 2 even smaller.

Copy link
Collaborator Author

@SergeiPavlov SergeiPavlov Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any throw code is big actually
MS also uses this ThrowHelper pattern over dotnet codebase
See https://dunnhq.com/posts/2022/throw-helper/


result.ValueColumns.AddRange(valueColumns);
result.SelectColumns = columnMap;
result.SelectColumns = columnMap.ToArray();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it better than before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Arrays are more lightweight than List<>
Index building is one-time operation. It is better to store the most efficient data structure

var valueBuilder = new ValueStringBuilder(expectedLength);
valueBuilder.Append(BatchBegin);
+ statements.Sum(static statement => statement.Length);
StringBuilder sb = new(BatchBegin, expectedLength);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a comment why ValueStringBuilder is not suitable.

Copy link
Collaborator Author

@SergeiPavlov SergeiPavlov Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid valueBuilder.Append(actualStatement.ToString());

We cannot append ReadOnlySpan<> to ref struct ValueStringBuilder
So I decided to return back to StringBuilder to save an allocation inside loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants