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

Draft
wants to merge 55 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

src/components/codeblocks/CodeblockMermaid.svelte Outdated Show resolved Hide resolved
wasm/src/graph.rs Show resolved Hide resolved
src/commands/list_index/index.ts Outdated Show resolved Hide resolved
src/components/EdgeLink.svelte Outdated Show resolved Hide resolved
src/components/EdgeLink.svelte Show resolved Hide resolved
src/components/NestedEdgeList.svelte Outdated Show resolved Hide resolved
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 :)

src/components/EdgeLink.svelte Outdated Show resolved Hide resolved
wasm/src/graph.rs Outdated Show resolved Hide resolved
wasm/src/graph.rs Outdated Show resolved Hide resolved
wasm/src/graph.rs Outdated Show resolved Hide resolved
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

src/components/page_views/TrailView.svelte Outdated Show resolved Hide resolved
src/components/side_views/Matrix.svelte Outdated Show resolved Hide resolved
src/components/side_views/TreeView.svelte Outdated Show resolved Hide resolved
wasm/src/graph_traversal.rs Show resolved Hide resolved
wasm/src/graph_traversal.rs Show resolved Hide resolved
@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.

wasm/src/graph_data.rs Outdated Show resolved Hide resolved
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.

Maybe I'm missing something, but it seems alot of the references explicit need to be inverted

const traversal_options = new TraversalOptions(
[file_path],
options.fields ?? [],
Copy link
Owner

Choose a reason for hiding this comment

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

Question here. Previously the fallback was []. Does your traversal treat an empty fields list as all fields allowed? Cause mine needed you to explicitly pass in the full list of fields, if that's what you wanted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

undefined is all fields, [] is none

Copy link
Owner

Choose a reason for hiding this comment

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

Ok call, I'll update my change to use undefined when necessary

@@ -79,21 +80,20 @@ impl EdgeData {
// the mapping that exist on the JS side are as follows
// "field" | "explicit" | "source" | "implied_kind" | "round"

// TODO: maybe change the attribute options so that the JS side better matches the data

// TODO(JS): maybe change the attribute options so that the JS side better matches the data
Copy link
Owner

Choose a reason for hiding this comment

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

I could've named it better, but with the TODO(RUST) comments, I more just meant TODOs left for this PR, not where the todo needs to be done :)

wasm/src/graph_data.rs Outdated Show resolved Hide resolved
wasm/src/graph_data.rs Outdated Show resolved Hide resolved
wasm/src/graph_data.rs Outdated Show resolved Hide resolved
wasm/src/graph_mermaid.rs Outdated Show resolved Hide resolved
wasm/src/utils.rs Show resolved Hide resolved
Comment on lines +75 to +77
if self.stopped() {
LOGGER.warn(&format!("PerfLogger {} is already stopped", self.name));
} else {
Copy link
Owner

Choose a reason for hiding this comment

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

If you double-check that it's not already stopped in this function, it feels unecessary to check this before calling self.stop() elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kind of, the check here is to make sure that the place that is calling this checked stopped before.

wasm/src/utils.rs Show resolved Hide resolved
wasm/tests/graph.rs Outdated Show resolved Hide resolved
@mProjectsCode
Copy link
Contributor Author

Yep, it seems i was quite tired when I made those last few commits and missed a lot of places 😅


export const update = () => {
const max_depth = options.depth[1] ?? DEFAULT_MAX_DEPTH;

const source_path = options["start-note"] || file_path || $active_file_store?.path || "";
Copy link
Owner

Choose a reason for hiding this comment

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

file_path is start-note, if present

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah ok

src/components/side_views/MatrixEdgeField.svelte Outdated Show resolved Hide resolved
Comment on lines 83 to 87
pub fn sort_edges(&self, graph: &NoteGraph, edges: &mut [EdgeStruct]) {
let ordering = self.get_edge_ordering(graph);

edges.sort_by(|a, b| self.apply_edge_ordering(&ordering, a, b));
edges.sort_by(|a, b| self.apply_edge_ordering(ordering.as_ref(), a, b));
}
Copy link
Owner

Choose a reason for hiding this comment

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

Are these clippy suggestions? What do they mean?

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 can explain this at some point in VC.

wasm/src/graph_mermaid.rs Outdated Show resolved Hide resolved
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, I like the use of getter_with_clone :)

Comment on lines +117 to +119
pub fn to_paths(&self) -> Vec<Path> {
self.paths.clone()
}
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't this just a getter on self.paths


#[wasm_bindgen]
#[derive(Clone, Debug)]
pub struct FlatRecTraversalResult {
Copy link
Owner

Choose a reason for hiding this comment

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

Just at a glance, can we use this same struct to handle the flatten method on RecTraversalData? It seems there's some duplicated logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's similar, but there are some differences, though the names are too close for my liking. Maybe they can be put into one method though,

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

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