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

perf: v8 code cache #23081

Merged
merged 23 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ pub struct Flags {
pub unstable_config: UnstableConfig,
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub v8_flags: Vec<String>,
pub code_cache_enabled: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

We do have negative-sense flags in this flags struct -- see no_npm, no_prompt, etc. It would simplify the test changes required for this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately big test change will still be needed in this file because we're only enabling code cache for run command initially.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up keeping this the same. With the negative no_code_cache flag there are actually more test changes needed (because code cache is disabled for non-run commands).

}

fn join_paths(allowlist: &[String], d: &str) -> String {
Expand Down Expand Up @@ -2208,6 +2209,7 @@ fn run_subcommand() -> Command {
.trailing_var_arg(true),
)
.arg(env_file_arg())
.arg(no_code_cache_arg())
.about("Run a JavaScript or TypeScript program")
.long_about(
"Run a JavaScript or TypeScript program
Expand Down Expand Up @@ -3194,6 +3196,13 @@ fn no_clear_screen_arg() -> Arg {
.help("Do not clear terminal screen when under watch mode")
}

fn no_code_cache_arg() -> Arg {
Arg::new("no-code-cache")
.long("no-code-cache")
.help("Disable V8 code cache feature")
.action(ArgAction::SetTrue)
}

fn watch_exclude_arg() -> Arg {
Arg::new("watch-exclude")
.long("watch-exclude")
Expand Down Expand Up @@ -3793,6 +3802,8 @@ fn run_parse(
) -> clap::error::Result<()> {
runtime_args_parse(flags, matches, true, true);

flags.code_cache_enabled = !matches.get_flag("no-code-cache");

let mut script_arg =
matches.remove_many::<String>("script_arg").ok_or_else(|| {
let mut app = app;
Expand Down
4 changes: 4 additions & 0 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,10 @@ impl CliOptions {
&self.flags.v8_flags
}

pub fn code_cache_enabled(&self) -> bool {
self.flags.code_cache_enabled
}

pub fn watch_paths(&self) -> Vec<PathBuf> {
let mut full_paths = Vec::new();
if let DenoSubcommand::Run(RunFlags {
Expand Down
2 changes: 1 addition & 1 deletion cli/cache/cache_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl CacheDB {
/// Query a row from the database with a mapping function.
pub fn query_row<T, F>(
&self,
sql: &'static str,
sql: &str,
params: impl Params,
f: F,
) -> Result<Option<T>, AnyError>
Expand Down
15 changes: 15 additions & 0 deletions cli/cache/caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use once_cell::sync::OnceCell;
use super::cache_db::CacheDB;
use super::cache_db::CacheDBConfiguration;
use super::check::TYPE_CHECK_CACHE_DB;
use super::code_cache::CODE_CACHE_DB;
use super::deno_dir::DenoDirProvider;
use super::fast_check::FAST_CHECK_CACHE_DB;
use super::incremental::INCREMENTAL_CACHE_DB;
Expand All @@ -22,6 +23,7 @@ pub struct Caches {
fast_check_db: OnceCell<CacheDB>,
node_analysis_db: OnceCell<CacheDB>,
type_checking_cache_db: OnceCell<CacheDB>,
code_cache_db: OnceCell<CacheDB>,
}

impl Caches {
Expand All @@ -34,6 +36,7 @@ impl Caches {
fast_check_db: Default::default(),
node_analysis_db: Default::default(),
type_checking_cache_db: Default::default(),
code_cache_db: Default::default(),
}
}

Expand Down Expand Up @@ -124,4 +127,16 @@ impl Caches {
.map(|dir| dir.type_checking_cache_db_file_path()),
)
}

pub fn code_cache_db(&self) -> CacheDB {
Self::make_db(
&self.code_cache_db,
&CODE_CACHE_DB,
self
.dir_provider
.get_or_create()
.ok()
.map(|dir| dir.code_cache_db_file_path()),
)
}
}