Skip to content

Commit

Permalink
Merge #6651
Browse files Browse the repository at this point in the history
6651: Profile completions better r=SomeoneToIgnore a=SomeoneToIgnore

During #6612 investigation, had added a few more profiling points and considered that they can be useful later, ergo the PR.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
  • Loading branch information
bors[bot] and SomeoneToIgnore committed Nov 27, 2020
2 parents c66d477 + 04cd4b1 commit 0993f90
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/assists/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
pub use insert_use::{insert_use, ImportScope, MergeBehaviour};

pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path {
let _p = profile::span("mod_path_to_ast");
let mut segments = Vec::new();
let mut is_abs = false;
match path.kind {
Expand Down
1 change: 1 addition & 0 deletions crates/assists/src/utils/insert_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub fn insert_use<'a>(
path: ast::Path,
merge: Option<MergeBehaviour>,
) -> SyntaxRewriter<'a> {
let _p = profile::span("insert_use");
let mut rewriter = SyntaxRewriter::default();
let use_item = make::use_(make::use_tree(path.clone(), None, None, false));
// merge into existing imports if possible
Expand Down
2 changes: 2 additions & 0 deletions crates/completion/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ pub(crate) struct Builder {

impl Builder {
pub(crate) fn build(self) -> CompletionItem {
let _p = profile::span("item::Builder::build");

let mut label = self.label;
let mut lookup = self.lookup;
let mut insert_text = self.insert_text;
Expand Down
1 change: 1 addition & 0 deletions crates/completion/src/render/enum_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) fn render_enum_variant<'a>(
variant: hir::EnumVariant,
path: Option<ModPath>,
) -> CompletionItem {
let _p = profile::span("render_enum_variant");
EnumVariantRender::new(ctx, local_name, variant, path).render(import_data)
}

Expand Down
1 change: 1 addition & 0 deletions crates/completion/src/render/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub(crate) fn render_fn<'a>(
local_name: Option<String>,
fn_: hir::Function,
) -> CompletionItem {
let _p = profile::span("render_fn");
FunctionRender::new(ctx, local_name, fn_).render(import_data)
}

Expand Down
1 change: 1 addition & 0 deletions crates/completion/src/render/macro_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) fn render_macro<'a>(
name: String,
macro_: hir::MacroDef,
) -> Option<CompletionItem> {
let _p = profile::span("render_macro");
MacroRender::new(ctx, name, macro_).render(import_data)
}

Expand Down
1 change: 1 addition & 0 deletions crates/syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ stdx = { path = "../stdx", version = "0.0.0" }
text_edit = { path = "../text_edit", version = "0.0.0" }
parser = { path = "../parser", version = "0.0.0" }
test_utils = { path = "../test_utils", version = "0.0.0" }
profile = { path = "../profile", version = "0.0.0" }

[dev-dependencies]
walkdir = "2.3.1"
Expand Down
13 changes: 13 additions & 0 deletions crates/syntax/src/algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ pub struct TreeDiff {

impl TreeDiff {
pub fn into_text_edit(&self, builder: &mut TextEditBuilder) {
let _p = profile::span("into_text_edit");

for (anchor, to) in self.insertions.iter() {
let offset = match anchor {
TreeDiffInsertPos::After(it) => it.text_range().end(),
Expand Down Expand Up @@ -154,6 +156,8 @@ impl TreeDiff {
///
/// This function tries to find a fine-grained diff.
pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
let _p = profile::span("diff");

let mut diff = TreeDiff {
replacements: FxHashMap::default(),
insertions: FxIndexMap::default(),
Expand Down Expand Up @@ -467,6 +471,8 @@ impl<'a> SyntaxRewriter<'a> {
}

pub fn rewrite(&self, node: &SyntaxNode) -> SyntaxNode {
let _p = profile::span("rewrite");

if self.f.is_none() && self.replacements.is_empty() && self.insertions.is_empty() {
return node.clone();
}
Expand All @@ -483,6 +489,7 @@ impl<'a> SyntaxRewriter<'a> {
///
/// Returns `None` when there are no replacements.
pub fn rewrite_root(&self) -> Option<SyntaxNode> {
let _p = profile::span("rewrite_root");
fn element_to_node_or_parent(element: &SyntaxElement) -> SyntaxNode {
match element {
SyntaxElement::Node(it) => it.clone(),
Expand Down Expand Up @@ -517,6 +524,8 @@ impl<'a> SyntaxRewriter<'a> {
}

fn rewrite_children(&self, node: &SyntaxNode) -> SyntaxNode {
let _p = profile::span("rewrite_children");

// FIXME: this could be made much faster.
let mut new_children = Vec::new();
if let Some(elements) = self.insertions(&InsertPos::FirstChildOf(node.clone())) {
Expand All @@ -533,6 +542,8 @@ impl<'a> SyntaxRewriter<'a> {
acc: &mut Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>,
element: &SyntaxElement,
) {
let _p = profile::span("rewrite_self");

if let Some(replacement) = self.replacement(&element) {
match replacement {
Replacement::Single(element) => acc.push(element_to_green(element)),
Expand Down Expand Up @@ -588,6 +599,8 @@ fn with_children(
parent: &SyntaxNode,
new_children: Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>,
) -> SyntaxNode {
let _p = profile::span("with_children");

let len = new_children.iter().map(|it| it.text_len()).sum::<TextSize>();
let new_node = rowan::GreenNode::new(rowan::SyntaxKind(parent.kind() as u16), new_children);
let new_root_node = parent.replace_with(new_node);
Expand Down

0 comments on commit 0993f90

Please sign in to comment.