This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 411
Improve performance of GC.stats
#2164
Closed
mihails-strasuns-sociomantic
wants to merge
1
commit into
dlang:master
from
mihails-strasuns-sociomantic:faster-stats
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /** | ||
| * Utility to simplify calculating `core.memory.GC.Stats` | ||
| * | ||
| * Copyright: D Language Foundation, 2018 | ||
| * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). | ||
| * Source: $(DRUNTIMESRC gc/stats.d) | ||
| */ | ||
| module gc.stats; | ||
|
|
||
| /** | ||
| Embeds `GC.Stats` instance and adds few simple wrapper methods | ||
| to maniplate it while doing some sanity checks. | ||
| */ | ||
| package(gc) struct GCStatsTracker | ||
| { | ||
| @nogc nothrow @safe pure: | ||
|
|
||
| import core.memory; | ||
| GC.Stats stats; | ||
|
|
||
| /** | ||
| Record new memory added to the GC pool from OS | ||
| Params: | ||
| bytes = amount of memory | ||
| */ | ||
| void added(size_t bytes) | ||
| { | ||
| this.stats.freeSize += bytes; | ||
| } | ||
|
|
||
| /** | ||
| Record memory returned from the GC pool to OS | ||
| Params: | ||
| bytes = amount of memory | ||
| */ | ||
| void removed(size_t bytes) | ||
| { | ||
| assert(this.stats.freeSize >= bytes); | ||
| this.stats.freeSize -= bytes; | ||
| } | ||
|
|
||
| /** | ||
| Record new chunk of allocations from the GC pool | ||
| Params: | ||
| bytes = amount of memory | ||
| */ | ||
| void allocated(size_t bytes) | ||
| { | ||
| assert(this.stats.freeSize >= bytes); | ||
| this.stats.freeSize -= bytes; | ||
| this.stats.usedSize += bytes; | ||
| } | ||
|
|
||
| /** | ||
| Record return of allocated memory to the GC pool | ||
| Params: | ||
| bytes = amount of memory | ||
| */ | ||
| void freed(size_t bytes) | ||
| { | ||
| assert(this.stats.usedSize >= bytes); | ||
| this.stats.freeSize += bytes; | ||
| this.stats.usedSize -= bytes; | ||
| } | ||
|
|
||
| /** | ||
| Reset stored GC stats | ||
| */ | ||
| void reset() | ||
| { | ||
| this.stats = this.stats.init; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function is performance critical, being about to turn this statement into a no-op is important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean,
pragma(inline)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By no-op I mean no code is generated for the statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid it is not possible -
GC.statsis supposed to work for every program at any moment of time, it is not controlled by version or runtime flag.Though considering how extremely expensive call to
allocis, I am not sure I understand concern about 2 extra integer additions either.