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

Closure killer iterate segment lanes #1162

Merged
merged 7 commits into from
Oct 4, 2021

Conversation

DaEgi01
Copy link
Contributor

@DaEgi01 DaEgi01 commented Oct 3, 2021

Killed IterateSegmentLanes with struct enumerators to simplify code and remove heap allocations.

…sed enumerator that returns LaneId and LaneIndex.
…rect foreach and as a base line for further improvement.
# Conflicts:
#	TLM/TLM/State/Flags.cs
#	TLM/TLM/Traffic/Impl/SegmentEnd.cs

Also did a rename from LaneIdAndLaneIndex to LaneIdAndIndex.
Copy link
Member

@krzychu124 krzychu124 left a comment

Choose a reason for hiding this comment

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

Looks good

@kianzarrin
Copy link
Collaborator

is this code used in performance critical part of the code?

@DaEgi01
Copy link
Contributor Author

DaEgi01 commented Oct 3, 2021

is this code used in performance critical part of the code?

I think so. I'd have to double check since I made the changes some time ago.

Copy link
Collaborator

@kvakvs kvakvs left a comment

Choose a reason for hiding this comment

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

Nice


[Benchmark]
public void Foreach_Direct() {
foreach (var item in new GetSegmentLaneIdsEnumerable(0, testLanes.Length, testLanes)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does that by any reason get optimized out? Or you benchmark in debug mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty loop body could be optimized out? Not sure how C# compiler handles empty loops

Copy link
Member

Choose a reason for hiding this comment

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

Foreach won't be optimized because it may have side effects

@DaEgi01 DaEgi01 merged commit 408bb7e into master Oct 4, 2021
@DaEgi01 DaEgi01 deleted the ClosureKiller_IterateSegmentLanes branch October 4, 2021 21:19
@originalfoo originalfoo added this to the 11.6.0 milestone Dec 23, 2021
@originalfoo originalfoo added the code cleanup Refactor code, remove old code, improve maintainability label Dec 23, 2021
@originalfoo originalfoo modified the milestones: 11.6.0, 11.6.1.3 Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Refactor code, remove old code, improve maintainability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants