Conversation
Author
|
@DocSvartz Please note, that I uploaded a better version of this as #1023. If you like that one, this one can be declined and closed. |
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.
The patch and text below are AI generated, but I submit them with the hope that they are useful. In our (big) project the compilation of our main mappers takes 4 minutes, this change reduced it to 1 minute. If you need anything else, please let me know!
Problem
ReflectionUtils.DropHiddenMembers creates a deferred intersection of member names, then calls Contains(member.Name) on that sequence for each member. Those calls repeatedly rebuild intersection state and revisit the source.
A deterministic regression test using three reflected properties reproduces the issue: full enumeration visits the source nine times, exceeding the expected bound of six.
Solution
Materialize the existing comparison-name sequence once per enumeration into a HashSet using StringComparer.Ordinal.
The remainder of the method is unchanged.
Behavior and scope
• Preserves case-sensitive matching, output order, duplicates, and first-current-member/MetadataToken selection for stable inputs.
• Preserves deferred execution and recomputation on subsequent enumerations.
• Materialization changes traversal timing and can increase upfront work when enumeration stops early.
• Does not make the entire method linear: the existing currentTypeMembers.First(...) lookup remains.
• No reflection caching, metadata-token identity changes, public API changes, dependency changes, or unrelated refactoring.
Tests
Adds ten MSTest/Shouldly tests covering hidden properties and fields, private-property/public-field hiding, case sensitivity, ordering and duplicates, empty inputs, deferred execution and recomputation, deterministic enumeration cost, first-current-member selection, and compiled mapping to new and existing destinations.
Reproduction:
dotnet test src/Mapster.Tests/Mapster.Tests.csproj -c Release -f net10.0 --filter FullyQualifiedName~WhenDroppingHiddenMembers --logger "console;verbosity=normal"Against upstream 4a8aaa4 in an isolated worktree: nine tests pass and the enumeration-cost regression fails with nine visits versus a bound of six. With this patch: all ten pass.