aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock57
-rw-r--r--crates/ra_db/Cargo.toml2
-rw-r--r--crates/ra_ide_api/Cargo.toml2
-rw-r--r--crates/ra_ide_api/src/db.rs11
-rw-r--r--crates/ra_ide_api/src/imp.rs49
-rw-r--r--crates/ra_ide_api/src/lib.rs9
-rw-r--r--crates/ra_ide_api/src/status.rs44
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs3
-rw-r--r--crates/ra_lsp_server/src/server_world.rs6
9 files changed, 152 insertions, 31 deletions
diff --git a/Cargo.lock b/Cargo.lock
index dc54edef6..628e431bd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -381,6 +381,11 @@ version = "1.0.6"
381source = "registry+https://github.com/rust-lang/crates.io-index" 381source = "registry+https://github.com/rust-lang/crates.io-index"
382 382
383[[package]] 383[[package]]
384name = "fs_extra"
385version = "1.1.0"
386source = "registry+https://github.com/rust-lang/crates.io-index"
387
388[[package]]
384name = "fsevent" 389name = "fsevent"
385version = "0.2.17" 390version = "0.2.17"
386source = "registry+https://github.com/rust-lang/crates.io-index" 391source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -552,6 +557,34 @@ version = "0.4.3"
552source = "registry+https://github.com/rust-lang/crates.io-index" 557source = "registry+https://github.com/rust-lang/crates.io-index"
553 558
554[[package]] 559[[package]]
560name = "jemalloc-ctl"
561version = "0.2.0"
562source = "registry+https://github.com/rust-lang/crates.io-index"
563dependencies = [
564 "jemalloc-sys 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
565 "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
566]
567
568[[package]]
569name = "jemalloc-sys"
570version = "0.1.8"
571source = "registry+https://github.com/rust-lang/crates.io-index"
572dependencies = [
573 "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
574 "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
575 "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
576]
577
578[[package]]
579name = "jemallocator"
580version = "0.1.9"
581source = "registry+https://github.com/rust-lang/crates.io-index"
582dependencies = [
583 "jemalloc-sys 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
584 "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
585]
586
587[[package]]
555name = "join_to_string" 588name = "join_to_string"
556version = "0.1.3" 589version = "0.1.3"
557source = "registry+https://github.com/rust-lang/crates.io-index" 590source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -890,7 +923,7 @@ dependencies = [
890 "ra_syntax 0.1.0", 923 "ra_syntax 0.1.0",
891 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 924 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
892 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 925 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
893 "salsa 0.10.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)", 926 "salsa 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
894 "test_utils 0.1.0", 927 "test_utils 0.1.0",
895] 928]
896 929
@@ -920,6 +953,8 @@ dependencies = [
920 "fst 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 953 "fst 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
921 "insta 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 954 "insta 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
922 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 955 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
956 "jemalloc-ctl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
957 "jemallocator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
923 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 958 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
924 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 959 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
925 "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 960 "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1061,7 +1096,7 @@ version = "0.1.1"
1061source = "registry+https://github.com/rust-lang/crates.io-index" 1096source = "registry+https://github.com/rust-lang/crates.io-index"
1062dependencies = [ 1097dependencies = [
1063 "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 1098 "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
1064 "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 1099 "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
1065] 1100]
1066 1101
1067[[package]] 1102[[package]]
@@ -1090,7 +1125,7 @@ name = "rand_hc"
1090version = "0.1.0" 1125version = "0.1.0"
1091source = "registry+https://github.com/rust-lang/crates.io-index" 1126source = "registry+https://github.com/rust-lang/crates.io-index"
1092dependencies = [ 1127dependencies = [
1093 "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 1128 "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
1094] 1129]
1095 1130
1096[[package]] 1131[[package]]
@@ -1128,7 +1163,7 @@ name = "rand_xorshift"
1128version = "0.1.1" 1163version = "0.1.1"
1129source = "registry+https://github.com/rust-lang/crates.io-index" 1164source = "registry+https://github.com/rust-lang/crates.io-index"
1130dependencies = [ 1165dependencies = [
1131 "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 1166 "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
1132] 1167]
1133 1168
1134[[package]] 1169[[package]]
@@ -1266,7 +1301,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1266 1301
1267[[package]] 1302[[package]]
1268name = "salsa" 1303name = "salsa"
1269version = "0.10.0-alpha5" 1304version = "0.10.0"
1270source = "registry+https://github.com/rust-lang/crates.io-index" 1305source = "registry+https://github.com/rust-lang/crates.io-index"
1271dependencies = [ 1306dependencies = [
1272 "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", 1307 "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1275,13 +1310,13 @@ dependencies = [
1275 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 1310 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
1276 "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 1311 "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
1277 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 1312 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
1278 "salsa-macros 0.10.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)", 1313 "salsa-macros 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
1279 "smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", 1314 "smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
1280] 1315]
1281 1316
1282[[package]] 1317[[package]]
1283name = "salsa-macros" 1318name = "salsa-macros"
1284version = "0.10.0-alpha5" 1319version = "0.10.0"
1285source = "registry+https://github.com/rust-lang/crates.io-index" 1320source = "registry+https://github.com/rust-lang/crates.io-index"
1286dependencies = [ 1321dependencies = [
1287 "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 1322 "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1868,6 +1903,7 @@ dependencies = [
1868"checksum filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df5c1a8c4be27e7707789dc42ae65976e60b394afd293d1419ab915833e646" 1903"checksum filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df5c1a8c4be27e7707789dc42ae65976e60b394afd293d1419ab915833e646"
1869"checksum flexi_logger 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bbd731387787f54fa333fa426e173fe42ea3d1123636b2b27ad802025fc5d182" 1904"checksum flexi_logger 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bbd731387787f54fa333fa426e173fe42ea3d1123636b2b27ad802025fc5d182"
1870"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" 1905"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
1906"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
1871"checksum fsevent 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c4bbbf71584aeed076100b5665ac14e3d85eeb31fdbb45fbd41ef9a682b5ec05" 1907"checksum fsevent 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c4bbbf71584aeed076100b5665ac14e3d85eeb31fdbb45fbd41ef9a682b5ec05"
1872"checksum fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a772d36c338d07a032d5375a36f15f9a7043bf0cb8ce7cee658e037c6032874" 1908"checksum fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a772d36c338d07a032d5375a36f15f9a7043bf0cb8ce7cee658e037c6032874"
1873"checksum fst 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "db72126ca7dff566cdbbdd54af44668c544897d9d3862b198141f176f1238bdf" 1909"checksum fst 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "db72126ca7dff566cdbbdd54af44668c544897d9d3862b198141f176f1238bdf"
@@ -1887,6 +1923,9 @@ dependencies = [
1887"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" 1923"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
1888"checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" 1924"checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358"
1889"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" 1925"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
1926"checksum jemalloc-ctl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e93b0f37e7d735c6b610176d5b1bde8e1621ff3f6f7ac23cdfa4e7f7d0111b5"
1927"checksum jemalloc-sys 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "bfc62c8e50e381768ce8ee0428ee53741929f7ebd73e4d83f669bcf7693e00ae"
1928"checksum jemallocator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9f0cd42ac65f758063fea55126b0148b1ce0a6354ff78e07a4d6806bc65c4ab3"
1890"checksum join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc7a5290e8c2606ce2be49f456d50f69173cb96d1541e4f66e34ac8b331a98f" 1929"checksum join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc7a5290e8c2606ce2be49f456d50f69173cb96d1541e4f66e34ac8b331a98f"
1891"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 1930"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
1892"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" 1931"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
@@ -1950,8 +1989,8 @@ dependencies = [
1950"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 1989"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
1951"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" 1990"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
1952"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" 1991"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
1953"checksum salsa 0.10.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)" = "8b5e2535d707dc5ced81106d3b71d806cfeef8a6e8a567472fde7ffd56b770dd" 1992"checksum salsa 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cad0e2348e2f80725b2980914a08a00267136c3ecf720896d3f7f08eef51e08f"
1954"checksum salsa-macros 0.10.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)" = "e7c5da4c649f6d4fc1864fcd9a379b1f7c6d570b278559c84a6e15981c949cc6" 1993"checksum salsa-macros 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c79744109df21b80aef1367669b0a9e4985bc966e76bf0e9321b222ec0b9fbb"
1955"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" 1994"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
1956"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" 1995"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
1957"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 1996"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml
index 2d39b77ed..3bae22c74 100644
--- a/crates/ra_db/Cargo.toml
+++ b/crates/ra_db/Cargo.toml
@@ -5,8 +5,8 @@ version = "0.1.0"
5authors = ["Aleksey Kladov <[email protected]>"] 5authors = ["Aleksey Kladov <[email protected]>"]
6 6
7[dependencies] 7[dependencies]
8salsa = "0.10.0"
8relative-path = "0.4.0" 9relative-path = "0.4.0"
9salsa = "0.10.0-alpha5"
10rustc-hash = "1.0" 10rustc-hash = "1.0"
11parking_lot = "0.7.0" 11parking_lot = "0.7.0"
12 12
diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml
index 79e473463..ad9dd2088 100644
--- a/crates/ra_ide_api/Cargo.toml
+++ b/crates/ra_ide_api/Cargo.toml
@@ -14,6 +14,8 @@ fst = "0.3.1"
14rustc-hash = "1.0" 14rustc-hash = "1.0"
15parking_lot = "0.7.0" 15parking_lot = "0.7.0"
16unicase = "2.2.0" 16unicase = "2.2.0"
17jemallocator = "0.1.9"
18jemalloc-ctl = "0.2.0"
17 19
18ra_syntax = { path = "../ra_syntax" } 20ra_syntax = { path = "../ra_syntax" }
19ra_ide_api_light = { path = "../ra_ide_api_light" } 21ra_ide_api_light = { path = "../ra_ide_api_light" }
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index 3da93ec35..6850811d7 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -1,4 +1,7 @@
1use std::sync::Arc; 1use std::{
2 sync::Arc,
3 time,
4};
2 5
3use ra_db::{ 6use ra_db::{
4 CheckCanceled, FileId, Canceled, SourceDatabase, 7 CheckCanceled, FileId, Canceled, SourceDatabase,
@@ -17,6 +20,8 @@ use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}};
17pub(crate) struct RootDatabase { 20pub(crate) struct RootDatabase {
18 runtime: salsa::Runtime<RootDatabase>, 21 runtime: salsa::Runtime<RootDatabase>,
19 interner: Arc<hir::HirInterner>, 22 interner: Arc<hir::HirInterner>,
23 pub(crate) last_gc: time::Instant,
24 pub(crate) last_gc_check: time::Instant,
20} 25}
21 26
22impl salsa::Database for RootDatabase { 27impl salsa::Database for RootDatabase {
@@ -33,6 +38,8 @@ impl Default for RootDatabase {
33 let mut db = RootDatabase { 38 let mut db = RootDatabase {
34 runtime: salsa::Runtime::default(), 39 runtime: salsa::Runtime::default(),
35 interner: Default::default(), 40 interner: Default::default(),
41 last_gc: time::Instant::now(),
42 last_gc_check: time::Instant::now(),
36 }; 43 };
37 db.set_crate_graph(Default::default()); 44 db.set_crate_graph(Default::default());
38 db.set_local_roots(Default::default()); 45 db.set_local_roots(Default::default());
@@ -46,6 +53,8 @@ impl salsa::ParallelDatabase for RootDatabase {
46 salsa::Snapshot::new(RootDatabase { 53 salsa::Snapshot::new(RootDatabase {
47 runtime: self.runtime.snapshot(self), 54 runtime: self.runtime.snapshot(self),
48 interner: Arc::clone(&self.interner), 55 interner: Arc::clone(&self.interner),
56 last_gc: self.last_gc.clone(),
57 last_gc_check: self.last_gc_check.clone(),
49 }) 58 })
50 } 59 }
51} 60}
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
index 399433a01..31e0f5d6d 100644
--- a/crates/ra_ide_api/src/imp.rs
+++ b/crates/ra_ide_api/src/imp.rs
@@ -1,4 +1,7 @@
1use std::sync::Arc; 1use std::{
2 sync::Arc,
3 time,
4};
2 5
3use hir::{ 6use hir::{
4 self, Problem, source_binder 7 self, Problem, source_binder
@@ -19,12 +22,14 @@ use crate::{
19 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, 22 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
20 Query, RootChange, SourceChange, SourceFileEdit, 23 Query, RootChange, SourceChange, SourceFileEdit,
21 symbol_index::{FileSymbol, SymbolsDatabase}, 24 symbol_index::{FileSymbol, SymbolsDatabase},
25 status::syntax_tree_stats
22}; 26};
23 27
28const GC_COOLDOWN: time::Duration = time::Duration::from_millis(100);
29
24impl db::RootDatabase { 30impl db::RootDatabase {
25 pub(crate) fn apply_change(&mut self, change: AnalysisChange) { 31 pub(crate) fn apply_change(&mut self, change: AnalysisChange) {
26 log::info!("apply_change {:?}", change); 32 log::info!("apply_change {:?}", change);
27 // self.gc_syntax_trees();
28 if !change.new_roots.is_empty() { 33 if !change.new_roots.is_empty() {
29 let mut local_roots = Vec::clone(&self.local_roots()); 34 let mut local_roots = Vec::clone(&self.local_roots());
30 for (root_id, is_local) in change.new_roots { 35 for (root_id, is_local) in change.new_roots {
@@ -72,18 +77,36 @@ impl db::RootDatabase {
72 self.set_source_root(root_id, Arc::new(source_root)); 77 self.set_source_root(root_id, Arc::new(source_root));
73 } 78 }
74 79
75 /// Ideally, we should call this function from time to time to collect heavy 80 pub(crate) fn maybe_collect_garbage(&mut self) {
76 /// syntax trees. However, if we actually do that, everything is recomputed 81 if self.last_gc_check.elapsed() > GC_COOLDOWN {
77 /// for some reason. Needs investigation. 82 self.last_gc_check = time::Instant::now();
83 let retained_trees = syntax_tree_stats(self).retained;
84 if retained_trees > 100 {
85 log::info!(
86 "automatic garbadge collection, {} retained trees",
87 retained_trees
88 );
89 self.collect_garbage();
90 }
91 }
92 }
93
78 pub(crate) fn collect_garbage(&mut self) { 94 pub(crate) fn collect_garbage(&mut self) {
79 self.query(ra_db::ParseQuery) 95 self.last_gc = time::Instant::now();
80 .sweep(SweepStrategy::default().discard_values()); 96
81 self.query(hir::db::HirParseQuery) 97 let sweep = SweepStrategy::default()
82 .sweep(SweepStrategy::default().discard_values()); 98 .discard_values()
83 self.query(hir::db::FileItemsQuery) 99 .sweep_all_revisions();
84 .sweep(SweepStrategy::default().discard_values()); 100
85 self.query(hir::db::FileItemQuery) 101 self.query(ra_db::ParseQuery).sweep(sweep);
86 .sweep(SweepStrategy::default().discard_values()); 102
103 self.query(hir::db::HirParseQuery).sweep(sweep);
104 self.query(hir::db::FileItemsQuery).sweep(sweep);
105 self.query(hir::db::FileItemQuery).sweep(sweep);
106
107 self.query(hir::db::LowerModuleQuery).sweep(sweep);
108 self.query(hir::db::LowerModuleSourceMapQuery).sweep(sweep);
109 self.query(hir::db::BodySyntaxMappingQuery).sweep(sweep);
87 } 110 }
88} 111}
89 112
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 43c8bea71..dc531e068 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -59,6 +59,11 @@ pub use ra_db::{
59 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId 59 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId
60}; 60};
61 61
62// We use jemalloc mainly to get heap usage statistics, actual performance
63// differnece is not measures.
64#[global_allocator]
65static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
66
62pub type Cancelable<T> = Result<T, Canceled>; 67pub type Cancelable<T> = Result<T, Canceled>;
63 68
64#[derive(Default)] 69#[derive(Default)]
@@ -286,6 +291,10 @@ impl AnalysisHost {
286 self.db.apply_change(change) 291 self.db.apply_change(change)
287 } 292 }
288 293
294 pub fn maybe_collect_garbage(&mut self) {
295 self.db.maybe_collect_garbage();
296 }
297
289 pub fn collect_garbage(&mut self) { 298 pub fn collect_garbage(&mut self) {
290 self.db.collect_garbage(); 299 self.db.collect_garbage();
291 } 300 }
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs
index e11eed223..c3e5745d5 100644
--- a/crates/ra_ide_api/src/status.rs
+++ b/crates/ra_ide_api/src/status.rs
@@ -15,9 +15,13 @@ use crate::{
15 symbol_index::{SymbolIndex, LibrarySymbolsQuery}, 15 symbol_index::{SymbolIndex, LibrarySymbolsQuery},
16}; 16};
17 17
18pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
19 db.query(ParseQuery).entries::<SyntaxTreeStats>()
20}
21
18pub(crate) fn status(db: &RootDatabase) -> String { 22pub(crate) fn status(db: &RootDatabase) -> String {
19 let files_stats = db.query(FileTextQuery).entries::<FilesStats>(); 23 let files_stats = db.query(FileTextQuery).entries::<FilesStats>();
20 let syntax_tree_stats = db.query(ParseQuery).entries::<SyntaxTreeStats>(); 24 let syntax_tree_stats = syntax_tree_stats(db);
21 let symbols_stats = db 25 let symbols_stats = db
22 .query(LibrarySymbolsQuery) 26 .query(LibrarySymbolsQuery)
23 .entries::<LibrarySymbolsStats>(); 27 .entries::<LibrarySymbolsStats>();
@@ -26,8 +30,13 @@ pub(crate) fn status(db: &RootDatabase) -> String {
26 interner.len() 30 interner.len()
27 }; 31 };
28 format!( 32 format!(
29 "{}\n{}\n{}\nn_defs {}\n", 33 "{}\n{}\n{}\n{} defs\n\nmemory:\n{}\ngc {:?} seconds ago",
30 files_stats, symbols_stats, syntax_tree_stats, n_defs 34 files_stats,
35 symbols_stats,
36 syntax_tree_stats,
37 n_defs,
38 MemoryStats::current(),
39 db.last_gc.elapsed().as_secs(),
31 ) 40 )
32} 41}
33 42
@@ -58,9 +67,9 @@ impl FromIterator<TableEntry<FileId, Arc<String>>> for FilesStats {
58} 67}
59 68
60#[derive(Default)] 69#[derive(Default)]
61struct SyntaxTreeStats { 70pub(crate) struct SyntaxTreeStats {
62 total: usize, 71 total: usize,
63 retained: usize, 72 pub(crate) retained: usize,
64 retained_size: Bytes, 73 retained_size: Bytes,
65} 74}
66 75
@@ -118,6 +127,31 @@ impl FromIterator<TableEntry<SourceRootId, Arc<SymbolIndex>>> for LibrarySymbols
118 } 127 }
119} 128}
120 129
130struct MemoryStats {
131 allocated: Bytes,
132 resident: Bytes,
133}
134
135impl MemoryStats {
136 fn current() -> MemoryStats {
137 jemalloc_ctl::epoch().unwrap();
138 MemoryStats {
139 allocated: Bytes(jemalloc_ctl::stats::allocated().unwrap()),
140 resident: Bytes(jemalloc_ctl::stats::resident().unwrap()),
141 }
142 }
143}
144
145impl fmt::Display for MemoryStats {
146 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
147 write!(
148 fmt,
149 "{} allocated {} resident",
150 self.allocated, self.resident,
151 )
152 }
153}
154
121#[derive(Default)] 155#[derive(Default)]
122struct Bytes(usize); 156struct Bytes(usize);
123 157
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index ddd20a41f..e430ac6de 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -172,6 +172,7 @@ fn main_loop_inner(
172 172
173 let (libdata_sender, libdata_receiver) = unbounded(); 173 let (libdata_sender, libdata_receiver) = unbounded();
174 loop { 174 loop {
175 state.maybe_collect_garbage();
175 log::trace!("selecting"); 176 log::trace!("selecting");
176 let event = select! { 177 let event = select! {
177 recv(msg_receiver) -> msg => match msg { 178 recv(msg_receiver) -> msg => match msg {
@@ -207,7 +208,7 @@ fn main_loop_inner(
207 }; 208 };
208 match req.cast::<req::CollectGarbage>() { 209 match req.cast::<req::CollectGarbage>() {
209 Ok((id, ())) => { 210 Ok((id, ())) => {
210 state.collect_garbadge(); 211 state.collect_garbage();
211 let resp = RawResponse::ok::<req::CollectGarbage>(id, &()); 212 let resp = RawResponse::ok::<req::CollectGarbage>(id, &());
212 msg_sender.send(RawMessage::Response(resp)).unwrap() 213 msg_sender.send(RawMessage::Response(resp)).unwrap()
213 } 214 }
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index bf04f1125..c2167c5d8 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -232,7 +232,11 @@ impl ServerWorldState {
232 } 232 }
233 } 233 }
234 234
235 pub fn collect_garbadge(&mut self) { 235 pub fn maybe_collect_garbage(&mut self) {
236 self.analysis_host.maybe_collect_garbage()
237 }
238
239 pub fn collect_garbage(&mut self) {
236 self.analysis_host.collect_garbage() 240 self.analysis_host.collect_garbage()
237 } 241 }
238} 242}