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

Performance: Counter/ProcessId/ThreadId-LayoutRenderer allocates less memory #1695

Merged
merged 1 commit into from
Oct 9, 2016

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Oct 9, 2016

These three renderers are using the invariant culture. - StringBuilder Append without allocation

This change is Reviewable

@codecov-io
Copy link

codecov-io commented Oct 9, 2016

Current coverage is 80% (diff: 100%)

Merging #1695 into master will increase coverage by <1%

@@             master      #1695   diff @@
==========================================
  Files           274        274          
  Lines         16871      16905    +34   
  Methods        2666       2669     +3   
  Messages          0          0          
  Branches       1871       1875     +4   
==========================================
+ Hits          13511      13543    +32   
- Misses         2928       2929     +1   
- Partials        432        433     +1   

Sunburst

Powered by Codecov. Last update 33b0bea...182c9dd

Copy link
Member

@304NotModified 304NotModified left a comment

Choose a reason for hiding this comment

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

What kind of garbage are we talking about? Garbage collector garbage?


// Calculate length of integer when written out
int length;
if (value >= 10000)
Copy link
Member

Choose a reason for hiding this comment

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

uhm, what about value / 10 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Less-than should be faster than division, and requires fewer iterations when larger values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I can revert, when testing then the profiler never picked up the ThreadIdLayoutRenderer whether using division-loop or if-less-than

Copy link
Member

Choose a reason for hiding this comment

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

That sounds like a premature optimization? Also we have now more less-than operations needed. My proposal is to replace the whole block with a single division (and some rounding up or down, dunno)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have removed the optimization and squashed the commits

[InlineData(1234567890)]
[InlineData(int.MaxValue)]
[InlineData(int.MinValue)]
void TestAppendInvariant(int input)
Copy link
Member

Choose a reason for hiding this comment

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

we're missing negative numbers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are inside the test-method. I subtract the value from 0.

Copy link
Member

Choose a reason for hiding this comment

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

missed that. Maybe rename the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have no special opinion. Have a good method name?

Copy link
Member

Choose a reason for hiding this comment

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

TestAppendInvariant_positive_and_negative :P

@snakefoot snakefoot changed the title ThreadIdLayoutRenderer - StringBuilder Append without garbage ThreadIdLayoutRenderer - StringBuilder Append without allocation Oct 9, 2016
@snakefoot
Copy link
Contributor Author

Changed the title from without garbage to without allocation

@304NotModified 304NotModified changed the title ThreadIdLayoutRenderer - StringBuilder Append without allocation Performance: ThreadIdLayoutRenderer allocations less memory Oct 9, 2016
@304NotModified
Copy link
Member

PS: I'm renaming the PRs so it is more suitable for the changelog.

@304NotModified 304NotModified changed the title Performance: ThreadIdLayoutRenderer allocations less memory Performance: Counter/ProcessId/ThreadId-LayoutRenderer allocations less memory Oct 9, 2016
@304NotModified 304NotModified added this to the 4.3.10 milestone Oct 9, 2016
@304NotModified 304NotModified merged commit 91e0391 into NLog:master Oct 9, 2016
@snakefoot snakefoot deleted the ThreaIdLayoutAppendInvariant branch October 9, 2016 23:16
@snakefoot snakefoot changed the title Performance: Counter/ProcessId/ThreadId-LayoutRenderer allocations less memory Performance: Counter/ProcessId/ThreadId-LayoutRenderer allocates less memory Oct 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants