Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Reading DXF files with many
VERTEXentities spends most of its time in reflection.DxfSectionReaderBase.readVertexcallsDxfClassMap.Create<T>()for every vertex;Createreturns a copy of the cached map, and theDxfPropertycopy constructor chains toDxfPropertyBase(PropertyInfo), which callsGetCustomAttribute<T>()again for every property. The attribute data is already available on the source property, so it is re-read needlessly once per property per vertex.This PR adds a protected copy constructor to
DxfPropertyBase<T>that reuses the source's_attributeData,_propertyand_assignedCode, and routes theDxfPropertycopy constructor through it.Results (large real-world DXF made up mostly of 3D polylines, Release build, runs interleaved over several rounds):
DxfReader.Read(warm, median)DxfReader.Read(first read in process)DxfReader.ReadEntitiesCustomAttribute.AddCustomAttributes(profiler)The entities read are identical before and after. On
net9.0andnet4.8, 2,415 of 2,417 existing tests pass and 2 are skipped.Tasks done in this PR
DxfCodeValueAttributevia reflection when copying aDxfProperty.Related Issues / Pull Requests
Notes for reviewer
Behaviour should be unchanged:
_attributeDataand_propertyare the same instances the old path would have looked up again._assignedCodemakesAssignedCoderesolve exactly as it did on the source (explicit code, single code, orInvalid).ValueCodes.Contains(code)validation is skipped. The source property already passed it when it was created.StoredValuewas not copied before and still isn't.Two follow-ups showed up while profiling, intentionally left out of this PR to keep it focused:
DxfPropertyBase.SetValueresolves the property type with anIsEquivalentTochain on every call, which is a large share of the remaining read time. Caching the type category once per property reduced it significantly.DxfClassMap.Createstill allocates a full map copy per vertex. The reader never mutates these maps, so it could use the cached instance directly.Happy to open separate PRs for either if they're of interest.