Skip to content

Commit bb75349

Browse files
committed
Intern known targets
1 parent 652844d commit bb75349

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ base64 = "0.12.1"
4646
strum = { version = "0.18.0", features = ["derive"] }
4747
lol_html = "0.2"
4848
dashmap = "3.11.10"
49+
string_cache = "0.8.0"
4950

5051
# Async
5152
tokio = { version = "0.2.22", features = ["rt-threaded"] }
@@ -93,6 +94,7 @@ rand = "0.7.3"
9394
time = "0.1"
9495
git2 = { version = "0.13", default-features = false }
9596
sass-rs = "0.2.2"
97+
string_cache_codegen = "0.5.1"
9698

9799
[[bench]]
98100
name = "html_parsing"

build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fn main() {
2828
panic!("Error compiling sass: {}", sass_err);
2929
}
3030
copy_js();
31+
write_known_targets().unwrap();
3132
}
3233

3334
fn write_git_version() {
@@ -108,3 +109,21 @@ fn copy_js() {
108109
fs::copy(&source_path, &dest_path).expect("Copy JavaScript file to target");
109110
});
110111
}
112+
113+
fn write_known_targets() -> std::io::Result<()> {
114+
use std::io::BufRead;
115+
116+
let targets: Vec<String> = std::process::Command::new("rustc")
117+
.args(&["--print", "target-list"])
118+
.output()?
119+
.stdout
120+
.lines()
121+
.filter(|s| s.as_ref().map_or(true, |s| !s.is_empty()))
122+
.collect::<std::io::Result<_>>()?;
123+
124+
string_cache_codegen::AtomType::new("target::TargetAtom", "target_atom!")
125+
.atoms(&targets)
126+
.write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join("target_atom.rs"))?;
127+
128+
Ok(())
129+
}

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ mod test;
2626
pub mod utils;
2727
mod web;
2828

29+
#[allow(dead_code)]
30+
mod target {
31+
//! [`crate::target::TargetAtom`] is an interned string type for rustc targets, such as
32+
//! `x86_64-unknown-linux-gnu`. See the [`string_cache`] docs for usage examples.
33+
include!(concat!(env!("OUT_DIR"), "/target_atom.rs"));
34+
}
35+
2936
use web::page::GlobalAlert;
3037

3138
// Warning message shown in the navigation bar of every page. Set to `None` to hide it.

src/metrics/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod macros;
33

44
use self::macros::MetricFromOpts;
55
use crate::db::Pool;
6+
use crate::target::TargetAtom;
67
use crate::BuildQueue;
78
use dashmap::DashMap;
89
use failure::Error;
@@ -81,7 +82,7 @@ metrics! {
8182
pub(crate) struct RecentlyAccessedReleases {
8283
krates: DashMap<i32, Instant>,
8384
versions: DashMap<i32, Instant>,
84-
platforms: DashMap<(i32, String), Instant>,
85+
platforms: DashMap<(i32, TargetAtom), Instant>,
8586
}
8687

8788
impl RecentlyAccessedReleases {
@@ -93,7 +94,7 @@ impl RecentlyAccessedReleases {
9394
self.krates.insert(krate, Instant::now());
9495
self.versions.insert(version, Instant::now());
9596
self.platforms
96-
.insert((version, target.to_owned()), Instant::now());
97+
.insert((version, TargetAtom::from(target)), Instant::now());
9798
}
9899

99100
pub(crate) fn gather(&self, metrics: &Metrics) {

0 commit comments

Comments
 (0)