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

this code very faster #539

Open
wants to merge 73 commits into
base: master
Choose a base branch
from

Conversation

mProjectsCode
Copy link
Contributor

🦀
(feel free to change the name of this PR)

@mProjectsCode
Copy link
Contributor Author

mProjectsCode commented Apr 27, 2024

TODO list:

  • make edge builder build the rust data directly
  • relevant settings get passed to rust
  • implement all features for mermaid code blocks
  • implement all features for tree view
  • fix all of the other views
  • get incremental graph rebuilds on vault events working => Separate PR
  • re-implement the transitive rule preview in the settings
  • fix the thread command
    • The target note needs to be created first, before trying to add the new edge to the graph
  • update the settings types so that the old types can be removed => Separate PR
    • e.g. implied_rule.chain uses a BCAttribute[], but only ever needs to be a string[] in practice
  • remove old commented out code
  • revive the markmap code block
  • improve graph updates via debouncing and aggregating into one batch update => Separate PR

Copy link
Owner

@SkepticMystic SkepticMystic left a comment

Choose a reason for hiding this comment

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

Looking good so far. I'm gonna try review frequently to keep the diff size small

Copy link
Owner

@SkepticMystic SkepticMystic left a comment

Choose a reason for hiding this comment

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

Nice, continues to get closer :)

Copy link
Owner

@SkepticMystic SkepticMystic left a comment

Choose a reason for hiding this comment

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

Nice, this is mcuh easier to understand now

@mProjectsCode
Copy link
Contributor Author

Some preliminary performance metrics. (Take with a grain of salt, as with all benchmarks.)
Tested with 2564 notes in a tree shape. Each note has 1 to 3 explicit up frontmatter links. The tree is cut off at depth 10.
Transitive rules:

[up] <- down
[down] <- up
[same] <- same
[uncle] <- nephew
[nephew] <- uncle
[up, down] -> same
[up, same] -> uncle

This fork:

  • Initial Graph: ~4ms
  • Implied Edges: ~2.5ms
  • Total: ~18ms

Current Master (4.2.27) after running a few times to get JIT advantages:

  • Implied Edges: ~70ms
  • Total: ~85ms

This fork is about 4x faster regarding total time and about 25x faster in building implied edges.

Copy link
Owner

@SkepticMystic SkepticMystic left a comment

Choose a reason for hiding this comment

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

Nice, looking good

@mProjectsCode
Copy link
Contributor Author

Did some optimizations:

  1. removed dyn in hot paths and replaced it with enums
  2. replaced String with Rc<str> since we have lots of the same small strings, we can use Rc, which only clones the pointer and not the string.

@mProjectsCode
Copy link
Contributor Author

I limited the tree view and trail view to depth 5 for now. The graph engine can easily handle more, but the rendering is too slow. There should be an indicator that a cut-off happened though.

@mProjectsCode
Copy link
Contributor Author

The total graph rebuilding time is now at ~15ms for a tree structure vault with 2.5k files.

@mProjectsCode
Copy link
Contributor Author

Some more progress:

  1. removed a lot of potential crash points in the Rust part, now they will throw a JS error
  2. updated to svelte 5
  3. some further minor optimizations

@mProjectsCode mProjectsCode marked this pull request as ready for review January 12, 2025 21:38
// Even tho we ensure the graph is built before the views are registered,
// Existing views still try render before the graph is built.
plugin.graph.has_node($active_file_store.path)
let active_file = $derived($active_file_store);
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not quite used to svelte 5 yet. Why do you need to make a reactive variable out of the store?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because stores are technically deprecated in svelte 5, and using them in certain contexts without making them a derived first can cause some strange issues like duplicated updates.

Comment on lines +26 to +37
let edge_sort_id = $state(plugin.settings.views.side.tree.edge_sort_id);
let merge_fields = $state(plugin.settings.views.side.tree.merge_fields);
let show_attributes = $state(
plugin.settings.views.side.tree.show_attributes,
);
let show_node_options = $state(
plugin.settings.views.side.tree.show_node_options,
);
let field_group_labels = $state(
plugin.settings.views.side.tree.field_group_labels,
);
let collapse = $state(plugin.settings.views.side.tree.collapse);
Copy link
Owner

Choose a reason for hiding this comment

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

In a different component, you destructured the settings off of $state(plugin.settings.something). Does that work here instead of defining separate variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The destructuring is wrong, as it breaks reactivity in svelte 5, but I could probably do one let view_settings = $state(plugin.settings.views.side.tree) and then use it like view_settings.edge_sort_id. That would also reduce the amount of $state.

}),
);
}

async onOpen() {
const container = this.containerEl.children[1];
container.empty();
Copy link
Owner

Choose a reason for hiding this comment

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

Does container.empty() call this.onClose() to unmount the component? Or does emptying the container properly destroy the component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, container.empty() only empties the element. I am not sure why the code is the way it is, seems like I didn't touch those lines.

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

Successfully merging this pull request may close these issues.

2 participants