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

BREAKING: rules::get_all_rules etc. return LintRules wrapped in Arc #845

Merged
merged 9 commits into from Sep 6, 2021

Conversation

magurotuna
Copy link
Member

This PR changes the return types of get_all_rules, get_recommended_rules, and get_filtered_rules to Arc-wrapped values.

This will allow us to instantiate LintRules just once before spawning worker threads, and then they are sharable across threads. Considering that instantiating rules is currently performed once per one file, which can be a significant amount of times if there are numerous lint target files, this will contribute to performance to some extent.

Comment on lines +313 to +314
let mut recommended_rules =
Arc::try_unwrap(get_recommended_rules()).unwrap();
Copy link
Member Author

Choose a reason for hiding this comment

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

A bunch of #[derive(Debug)] for all the lint structs are required to call unwrap here.

Comment on lines +106 to 122
#[derive(Debug)]
pub struct PluginRunner {
plugin_path: String,
}

impl PluginRunner {
pub fn new(plugin_path: &str) -> Box<Self> {
Box::new(Self {
plugin_path: plugin_path.to_string(),
})
}
}

struct JsRunner {
runtime: JsRuntime,
module_id: i32,
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Previous JsRuleRunner struct can neither be Send nor Sync because of JsRuntime. So I split it into two, one is PluginRunner, which is thread safe, the other is JsRunner, which is not.
What we'll share across worker threads is PluginRunner only.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @magurotuna this is very desired change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants