Skip to content

Commit cd36fc1

Browse files
authored
Merge pull request #79 from lnicola/patch-1
Grammar nits
2 parents b762e88 + 1cdb5b3 commit cd36fc1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

blog/_posts/2020-12-04-measuring-memory-usage-in-rust.adoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ _The second approach_ is based on instrumenting the calls to allocation and deal
2626
The profiler captures backtraces when the program calls `malloc` and `free` and constructs a flamegraph displaying "`hot`" functions which allocate a lot.
2727
This is how, for example, https://github.com/KDE/heaptrack[heaptrack] works (see also https://github.com/cuviper/alloc_geiger[alloc geiger]).
2828

29-
The two approaches are complimentary.
30-
If the problem is that the application does to many short-lived allocations (instead of re-using the buffers), it would be invisible for the first approach, but very clear in the second one.
29+
The two approaches are complementary.
30+
If the problem is that the application does too many short-lived allocations (instead of re-using the buffers), it would be invisible for the first approach, but very clear in the second one.
3131
If the problem is that, in a steady state, the application uses to much memory, the first approach would work better for pointing out which data structures need most attention.
3232

3333
In rust-analyzer, we are generally interested in keeping the overall memory usage small, and can make better use of heap parsing approach.
@@ -40,7 +40,7 @@ There is Servo's https://github.com/servo/servo/tree/2d3811c21bf1c02911d5002f967
4040

4141
Another alternative is running the program under valgrind to gain runtime introspectability.
4242
https://www.valgrind.org/docs/manual/ms-manual.html[Massif] and and https://www.valgrind.org/docs/manual/dh-manual.html[DHAT] work that way.
43-
Running with valgrind is pretty slow, and still doesn't give the Java-level fidelity.
43+
Running with valgrind is pretty slow, and still doesn't give Java-level fidelity.
4444

4545
Instead, rust-analyzer mainly relies on a much simpler approach for figuring out which things are heavy.
4646
This is the first trick of this article:
@@ -53,11 +53,11 @@ It's even possible to implement a https://doc.rust-lang.org/stable/std/alloc/tra
5353

5454
And, if you can measure total memory usage, you can measure memory usage of any specific data structure by:
5555

56-
. noting the current memory usage
56+
. measuring the current memory usage
5757
. dropping the data structure
58-
. noting the current memory usage again
58+
. measuring the current memory usage again
5959

60-
The difference between the two measurements is the size of the data structure.
60+
The difference between the two values is the size of the data structure.
6161
And this is exactly what rust-analyzer does to find the largest caches: https://github.com/rust-analyzer/rust-analyzer/blob/b988c6f84e06bdc5562c70f28586b9eeaae3a39c/crates/ide_db/src/apply_change.rs#L104-L238[source].
6262

6363
Two small notes about this method:
@@ -115,4 +115,4 @@ struct Name {
115115

116116
Now, if the new `Name` increases the overall memory consumption by `N`, we can estimate the total size of old ``Name``s as `N` as well, as they are twice as small.
117117

118-
Sometimes, quick and simple hacks works better than the finest instruments :)
118+
Sometimes, quick and simple hacks works better than the finest instruments :).

0 commit comments

Comments
 (0)