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

Add LRU Session Cache to Reduce RAM Usage #6239

Merged
merged 6 commits into from
Jul 10, 2024
Merged

Add LRU Session Cache to Reduce RAM Usage #6239

merged 6 commits into from
Jul 10, 2024

Conversation

JoshuaBatty
Copy link
Member

@JoshuaBatty JoshuaBatty commented Jul 8, 2024

Description

This PR introduces an LRU (Least Recently Used) cache mechanism for managing sessions in large workspaces. This change aims to address the issue of high RAM usage reported in workspaces with multiple projects.

closes #6222

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@JoshuaBatty JoshuaBatty requested a review from a team as a code owner July 8, 2024 06:03
@JoshuaBatty JoshuaBatty self-assigned this Jul 8, 2024
@JoshuaBatty JoshuaBatty added the language server LSP server label Jul 8, 2024
@JoshuaBatty JoshuaBatty marked this pull request as draft July 8, 2024 06:16
Copy link

github-actions bot commented Jul 8, 2024

Benchmark for 9188c18

Click to view benchmark
Test Base PR %
code_action 5.0±0.03ms 5.0±0.07ms 0.00%
code_lens 304.1±8.84ns 286.3±9.58ns -5.85%
compile 2.6±0.03s 2.6±0.05s 0.00%
completion 4.5±0.07ms 4.5±0.01ms 0.00%
did_change_with_caching 2.5±0.02s 2.5±0.02s 0.00%
document_symbol 928.3±15.81µs 859.7±12.96µs -7.39%
format 71.5±0.78ms 70.5±0.83ms -1.40%
goto_definition 340.7±14.98µs 342.5±6.36µs +0.53%
highlight 8.7±0.03ms 8.7±0.11ms 0.00%
hover 491.3±6.57µs 489.9±5.52µs -0.28%
idents_at_position 117.3±0.24µs 116.9±0.69µs -0.34%
inlay_hints 633.4±29.19µs 633.9±26.72µs +0.08%
on_enter 450.2±13.62ns 470.1±13.35ns +4.42%
parent_decl_at_position 3.5±0.05ms 3.6±0.05ms +2.86%
prepare_rename 337.0±7.22µs 341.4±6.24µs +1.31%
rename 8.9±0.11ms 8.9±0.15ms 0.00%
semantic_tokens 1253.9±15.23µs 1222.4±10.17µs -2.51%
token_at_position 332.4±1.62µs 331.5±2.08µs -0.27%
tokens_at_position 3.5±0.02ms 3.5±0.04ms 0.00%
tokens_for_file 399.6±8.34µs 407.5±4.44µs +1.98%
traverse 38.3±0.75ms 38.4±1.05ms +0.26%

Copy link

Benchmark for 4d3a6ba

Click to view benchmark
Test Base PR %
code_action 5.2±0.07ms 5.3±0.28ms +1.92%
code_lens 287.2±7.76ns 295.4±6.86ns +2.86%
compile 2.6±0.03s 2.6±0.02s 0.00%
completion 4.7±0.04ms 4.7±0.05ms 0.00%
did_change_with_caching 2.6±0.02s 2.6±0.03s 0.00%
document_symbol 912.7±42.70µs 969.0±40.43µs +6.17%
format 72.3±0.83ms 71.2±0.92ms -1.52%
goto_definition 329.3±7.31µs 336.3±5.68µs +2.13%
highlight 9.0±0.01ms 9.0±0.11ms 0.00%
hover 486.6±13.19µs 496.9±7.71µs +2.12%
idents_at_position 118.9±0.25µs 119.0±1.27µs +0.08%
inlay_hints 625.9±17.67µs 635.2±19.34µs +1.49%
on_enter 449.2±13.61ns 463.8±6.73ns +3.25%
parent_decl_at_position 3.7±0.05ms 3.7±0.04ms 0.00%
prepare_rename 333.0±6.06µs 335.8±3.79µs +0.84%
rename 9.4±0.10ms 9.3±0.09ms -1.06%
semantic_tokens 1270.3±13.87µs 1270.4±16.80µs +0.01%
token_at_position 334.5±2.40µs 328.9±2.13µs -1.67%
tokens_at_position 3.7±0.02ms 3.7±0.03ms 0.00%
tokens_for_file 397.4±1.53µs 403.0±2.26µs +1.41%
traverse 37.7±0.70ms 38.0±1.01ms +0.80%

Copy link

Benchmark for 6361215

Click to view benchmark
Test Base PR %
code_action 5.2±0.01ms 5.2±0.07ms 0.00%
code_lens 287.5±8.56ns 290.2±19.63ns +0.94%
compile 2.6±0.03s 2.6±0.03s 0.00%
completion 4.7±0.07ms 4.6±0.01ms -2.13%
did_change_with_caching 2.5±0.02s 2.6±0.03s +4.00%
document_symbol 913.3±65.86µs 874.3±18.93µs -4.27%
format 70.8±1.04ms 71.5±1.01ms +0.99%
goto_definition 347.2±5.64µs 346.3±3.18µs -0.26%
highlight 9.0±0.12ms 9.1±0.08ms +1.11%
hover 497.3±5.92µs 495.5±5.83µs -0.36%
idents_at_position 118.0±0.41µs 117.7±0.74µs -0.25%
inlay_hints 645.6±10.30µs 641.0±20.51µs -0.71%
on_enter 459.6±17.72ns 469.6±17.20ns +2.18%
parent_decl_at_position 3.7±0.02ms 3.7±0.02ms 0.00%
prepare_rename 341.8±7.35µs 347.4±7.25µs +1.64%
rename 9.3±0.08ms 9.3±0.08ms 0.00%
semantic_tokens 1262.4±58.70µs 1243.7±10.58µs -1.48%
token_at_position 333.6±2.21µs 330.5±2.46µs -0.93%
tokens_at_position 3.7±0.05ms 3.7±0.10ms 0.00%
tokens_for_file 396.7±1.94µs 399.1±1.92µs +0.60%
traverse 36.6±0.54ms 36.8±1.08ms +0.55%

@JoshuaBatty JoshuaBatty marked this pull request as ready for review July 10, 2024 03:29
@JoshuaBatty JoshuaBatty requested a review from a team July 10, 2024 03:29
Copy link

Benchmark for 5cc7639

Click to view benchmark
Test Base PR %
code_action 5.2±0.01ms 5.2±0.01ms 0.00%
code_lens 279.4±10.20ns 288.3±8.90ns +3.19%
compile 2.6±0.02s 2.6±0.02s 0.00%
completion 4.7±0.01ms 4.7±0.07ms 0.00%
did_change_with_caching 2.5±0.05s 2.6±0.02s +4.00%
document_symbol 870.4±22.57µs 866.3±31.89µs -0.47%
format 71.1±0.88ms 71.1±1.13ms 0.00%
goto_definition 344.2±7.85µs 337.6±6.80µs -1.92%
highlight 9.0±0.13ms 9.0±0.02ms 0.00%
hover 494.4±4.37µs 488.0±6.01µs -1.29%
idents_at_position 120.9±0.27µs 120.9±1.20µs 0.00%
inlay_hints 642.8±8.38µs 638.0±22.84µs -0.75%
on_enter 481.6±9.27ns 461.7±11.80ns -4.13%
parent_decl_at_position 3.7±0.02ms 3.7±0.03ms 0.00%
prepare_rename 343.8±7.61µs 335.8±3.69µs -2.33%
rename 9.3±0.09ms 9.3±0.12ms 0.00%
semantic_tokens 1262.2±22.22µs 1249.4±15.71µs -1.01%
token_at_position 340.4±4.55µs 330.1±1.75µs -3.03%
tokens_at_position 3.7±0.03ms 3.7±0.03ms 0.00%
tokens_for_file 396.5±7.80µs 395.8±2.86µs -0.18%
traverse 38.4±0.79ms 39.1±1.26ms +1.82%

Copy link
Member

@kayagokalp kayagokalp left a comment

Choose a reason for hiding this comment

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

Nice, I guess we were holding on to all sessions before this one. Do we have a benchmark we are running against to see mem usage? Maybe we can add that to CI run report once we have some headspace.

@JoshuaBatty
Copy link
Member Author

JoshuaBatty commented Jul 10, 2024

Nice, I guess we were holding on to all sessions before this one. Do we have a benchmark we are running against to see mem usage? Maybe we can add that to CI run report once we have some headspace.

Nothing concrete. I was just looking at activity monitor and seeing the memory usage between clicking into new projects in the FUSD workspace. Previously we just kept adding more without a cap. opening 20 projects in that repo got to about 30gb so about 660mb per project. This should at least keep us 2-3gb usage range now.

But strongly agree that adding a CI step for this would be very useful if we can find the capacity to implement it.

@IGI-111 IGI-111 enabled auto-merge (squash) July 10, 2024 05:21
@IGI-111 IGI-111 merged commit 250666d into master Jul 10, 2024
36 checks passed
@IGI-111 IGI-111 deleted the josh/lru_sessions branch July 10, 2024 05:35
Copy link

Benchmark for 168f9fb

Click to view benchmark
Test Base PR %
code_action 5.3±0.08ms 5.3±0.10ms 0.00%
code_lens 280.0±8.39ns 288.2±4.43ns +2.93%
compile 2.7±0.04s 2.7±0.03s 0.00%
completion 4.7±0.06ms 4.8±0.13ms +2.13%
did_change_with_caching 2.6±0.05s 2.7±0.06s +3.85%
document_symbol 851.4±18.93µs 945.6±38.69µs +11.06%
format 74.4±2.62ms 72.4±1.72ms -2.69%
goto_definition 334.7±7.39µs 344.7±7.42µs +2.99%
highlight 9.0±0.09ms 9.0±0.16ms 0.00%
hover 482.4±5.75µs 490.5±5.27µs +1.68%
idents_at_position 119.0±4.45µs 118.9±0.68µs -0.08%
inlay_hints 636.8±22.43µs 648.8±23.37µs +1.88%
on_enter 480.1±16.98ns 461.5±22.84ns -3.87%
parent_decl_at_position 3.7±0.04ms 3.7±0.03ms 0.00%
prepare_rename 333.6±7.86µs 338.7±6.51µs +1.53%
rename 9.6±0.14ms 9.6±0.16ms 0.00%
semantic_tokens 1226.1±28.38µs 1307.8±11.98µs +6.66%
token_at_position 336.8±2.71µs 334.6±2.35µs -0.65%
tokens_at_position 3.7±0.03ms 3.7±0.02ms 0.00%
tokens_for_file 401.9±2.47µs 399.0±5.32µs -0.72%
traverse 38.4±0.66ms 39.2±1.20ms +2.08%

esdrubal pushed a commit that referenced this pull request Aug 13, 2024
## Description
This PR introduces an LRU (Least Recently Used) cache mechanism for
managing sessions in large workspaces. This change aims to address the
issue of high RAM usage reported in workspaces with multiple projects.

closes #6222

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use a LRU mechanism for “forgetting” old sessions to reduce RAM usage for large workspaces.
3 participants