trganda / obsidian-attachment-management

Attachment Management of Obsidian
MIT License
142 stars 8 forks source link

Since installing Obsidian 1.6.0, the File nav tree (left) takes very long time (~20s) to appear on launch #120

Open luckman212 opened 1 month ago

luckman212 commented 1 month ago

I am not sure why, but with Attachment Management enabled, the file explorer tree on the left appears completely blank for a long time after launch of Obsidian.

I tested this on 2 separate computers, both Obsidian 1.6.0, and with NO other extensions enabled.

This is what the UI looks like during that time

image

After some time, the file list appears. There is nothing additional shown in the Console (debug log).

luckman212 commented 1 month ago

https://forum.obsidian.md/t/since-1-6-0-file-navigator-takes-15-20-seconds-to-appear-with-specific-plugin-loaded/81696

itoldusoandso commented 1 month ago

In the meantime you can try Attachment MANAGER plugin in the meantime which can move attachments and you can use Attachment Name Formatting plugin to rename attachments (except if you are saving attachments into a subfolder in the attachments folder, then renaming attachments doesn't work).

luckman212 commented 1 month ago

@itoldusoandso Thank you but I did try that and it doesn't work for my vault which is already heavily organized with attachment subfolders.

luckman212 commented 1 month ago

I started debugging on my own because I don't know if @trganda is around much

I bisected the initializing functions in main.ts until I found the one causing the huge delay. I then added a simple console log here

https://github.com/trganda/obsidian-attachment-management/blob/a764324954defba3be2ae781301643fdb281d330/src/main.ts#L158

>>> console.log("in onLayoutReady!");

I see there's some crazy recursion going on, the func is called 6744 times when Obsidian starts! It feels like an Obsidian bug, since the plugin code hasn't changed, but I don't know if we can work around it somehow, or why onLayoutReady() is being called so often.

screenshot_8NkdMLpY

luckman212 commented 1 month ago

Here's a perf graph captured during a long load

image

Zooming in at/near the moment when the file tree appears

image

all this is just 1000s of iterations to onLayoutReady()

image

image

luckman212 commented 1 month ago

I forked the repo and created a fix for this bug. I don't know if it's correct, but please check out https://github.com/luckman212/obsidian-attachment-management/commit/205362a46bdd778b580c7a2fa8424d1a17028132?diff=unified&w=1

So far it's working for me!

If anyone else wants to test:

  1. clone the https://github.com/luckman212/obsidian-attachment-management repo
  2. run npm i followed by npm run build
  3. Copy main.js, manifest.json and styles.css to your Obsidian plugins folder/obsidian-attachment-management (replacing the originals)
trganda commented 1 month ago

Tks for @luckman212 working. I have no right to using Obsidian v1.6.0 at this time, since I'm not the VIP user (accessing early verison) of Obsidian.

I will checking your fix, and if everything ok I will add it to this repo.

luckman212 commented 1 month ago

Ah ok @trganda thank you. Hopefully they make 1.6 public soon.

I've been using the patched version for a couple of days now and it's working fine for me. I submitted my change as a pull request: #123.

trganda commented 1 month ago

I have merged PR and released a new version.

luckman212 commented 1 month ago

@trganda One small thing, I realize I left a debug message in that commit, you may want to remove it. It's here:

https://github.com/trganda/obsidian-attachment-management/blob/4f3802b8b576074604571589055749b7b130e656/src/main.ts#L33

luckman212 commented 3 weeks ago

@trganda Just a quick note that 1.6.2 is now publicly available to all.

trganda commented 3 weeks ago

Tks for your tips, I will update and try to adapt the new version.