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

Some string.Intern's for minimizing duplicate strings count #3640

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

AlexanderKot
Copy link

After startup application that I develop now has ~9% of duplicate strings from all allocated objects.
1st consumer is ASP.NET MVC routing, NHib related strings seems on 2d place
image
and many others

Value Wasted Count CountAfter
System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e 491,36 KB 2420 2
System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e 281,78 KB 1375 2
NHibernate.Envers.Entities.RevisionTypeType, NHibernate.Envers, Version=5.5.2.0, Culture=neutral, PublicKeyToken=e2c5b946037fb7f8 212,9 KB 846
Int64 8,41 KB 862 8
Int32 6,97 KB 715 6

image
Minimized by interning SimpleValue.typeName

Value Wasted Count CountAfter
NN.Core.BL.NhibTune.IdGenerators.LongIdGenerator, Core.BL, Version=9.0.0.1, Culture=neutral, PublicKeyToken=null 61,25 KB 281 -

image
Minimized by interning SimpleValue.identifierGeneratorStrategy

Value Wasted Count CountAfter
originalId.REV 55,21 KB 2020 -
originalId.REV.id 16,77 KB 506 2
originalId.REV.Id 16,73 KB 505 -

image
image
image
Minimized by interning in
AbstractPropertyMapping .ExtendPath
EntityMetamodel.MapIdentifierPropertyTypes
AbstractEntityPersister. InitSubclassPropertyAliasesMap

Value Wasted Count CountAfter
0_ 31,14 KB 7973 -
1_ 2,75 KB 704 6

image
image
image
Minimized by generating suffix with interning
StringHelper.GenerateSuffix

Value Wasted Count CountAfter
Id 8,57 KB 2195 1867
REV 5,68 KB 970 506

image
image
Some minimization by interning Property.name

Value Wasted Count CountAfter
property 79,38 KB 5081 507

image
Some minimization by interning Property.propertyAccessorName

Value Wasted Count CountAfter
all,delete-orphan 6,14 KB 186 -

image
Minimized by interning Property.cascade

Value Wasted Count
NHibernate.Type.EnumType`1[[..RateType, .., Culture=neutral, PublicKeyToken=null]], NHibernate 27,42 KB 102
NHibernate.Type.EnumType`1[[..DayCountBasis, .., Culture=neutral, PublicKeyToken=null]], NHibernate 19,97 KB 72
NHibernate.Type.EnumType`1[[..DefaultViewType, .., Culture=neutral, PublicKeyToken=null]], NHibernate 17,61 KB 55

And many other similar
image
Some minimization by interning EnumType.typeName

Current result ~ 50K duplicates removed
image

Alexander Kot added 2 commits January 19, 2025 20:02

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@AlexanderKot AlexanderKot marked this pull request as ready for review January 19, 2025 22:00
@AlexanderKot
Copy link
Author

Unfortunately have no idea how optimize next duplicates

Value Wasted Count
AND REV = 55,77 KB 2597
AND VER = 53,82 KB 2506
‘, ‘ 49,55 KB 12685
‘)’ 3,71 KB 1899

image

Alexander Kot and others added 2 commits January 20, 2025 12:30
@AlexanderKot
Copy link
Author

If next code acceptable or too dirty for minimizing ', ' and ')' duplicates?

SqlString
private struct Part : IEquatable<Part>
{
	
	public Part(int sqlIndex, string content)
	{
		SqlIndex = sqlIndex;

		if (content.Length == 1 && content == StringHelper.ClosedParen)
			Content = StringHelper.ClosedParen;
		else if (content.Length == 2 && content == StringHelper.CommaSpace)
			Content = StringHelper.CommaSpace;
		else 
			Content = content;

		IsParameter = false;
	}
}

@AlexanderKot
Copy link
Author

Can I add there additional optimization for sparse arrays, or need create new PR?

@hazzik
Copy link
Member

hazzik commented Feb 6, 2025

Smaller the PR faster is review, so a new PR would be better.

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.

None yet

2 participants