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

[CLOSED] Linting can get re-run many extra times if you've viewed files outside your project #6067

Open
core-ai-bot opened this issue Aug 30, 2021 · 11 comments

Comments

@core-ai-bot
Copy link
Member

Issue by peterflynn
Wednesday Jan 29, 2014 at 01:25 GMT
Originally opened as adobe/brackets#6676


This is a regression that I think we should fix in Sprint 36:

  1. Put a log statement in CodeInspection.run()
  2. Open a file outside the project
  3. Switch to/from this file several times

Result:
CodeInspection runs many extra times: each time you switch between an external file and a project file, the number of times it's run increases by one. (But that number sticks: each file switch even within the project will then run CodeInspection N times).

Eventually switching files becomes noticeably slower (extra 1+ sec per switch).

Expected:
CodeInspection only runs once per currentDocumentChange.

This is happening because a no-op pref change event is sent, causing toggleEnabled(true) to get called when _enabled is already true, which in turn redundantly re-registers the listener. We should either make toggleEnabled() short-circuit out of no-op changes, or make updateListeners() robust to redundant calls (e.g. if it used a function outside its closure then jQuery wouldn't register it multiple times).

@dangoor Do you have cycles to take this? I worry that there may be more cases similar to this -- functions that previously never encountered no-ops now encountering them due to prefs. I think we should do a quick scrub of all the pref-change listeners to check for this...

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Wednesday Jan 29, 2014 at 01:27 GMT


Added to Kanban board too

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Wednesday Jan 29, 2014 at 01:41 GMT


There's a subtler issue here too: the old code relied on a single no-op change at the beginning to set up its event listeners. If we fix toggleEnabled() to ignore no-ops, it will never do that. So I think we should change _enabled to be initialized to false rather than true.

But this issue is easy to miss, since even without the change CodeInspection will still run anyway. I think this is because there's a second instance of this bug in the JSLint main.js -- on every currentDocumentChange it gets a no-op prefs change, which in turn causes it to call requestRun(), an alias for run(). We should probably fix that too...

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Wednesday Jan 29, 2014 at 01:45 GMT


Although I'm also confused as to why the prefs system is generating a no-op in the latter case (JSLint main.js) given that in this case you don't have to switch to a file outside the project. Is the problem that we simply can't tell for complex-valued prefs whether there's a diff or not? Seems like that could become a broader problem.

I wonder if, as part of #6578, we should change prefs events so that they're are only fired when you switch projects or make an actual pref edit. (Only clients passing the special CURRENT_FILE value would care about the remaining cases, and that seems like a rare enough use case that I wonder if we should have a separate event so people have to explicitly opt in to that bigger firehose).

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Wednesday Jan 29, 2014 at 01:54 GMT


@peterflynn Yeah, I can take a look into this, and I appreciate you diving in and checking it out also.

It was at your suggestion that the prefs system notifies for possible changes rather than notifying of specific changes. So, the current system notifies whenever it sees something that might have changed.

You're correct, though, that the receiver of that event has to be careful to not do the wrong thing when it receives such an event.

I'll investigate this problem and think about a minimal solution and how this intersects with #6578.

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Wednesday Jan 29, 2014 at 03:03 GMT


I don't think this particular issue intersects with #6578 because CodeInspection and JSLint both care about the current file and the current behavior of a prefs.get is, I believe, equivalent to CURRENT_FILE.

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Wednesday Jan 29, 2014 at 03:24 GMT


I searched through the code and don't see any similar issues, barring #6578. QuickView already checks if there was an actual change in the enabled value.

Pull request coming up.

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Wednesday Jan 29, 2014 at 17:57 GMT


Great catch! FBNC to@peterflynn

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Wednesday Feb 05, 2014 at 21:48 GMT


I'm now seeing CodeInspection run twice per file switch all the time, regardless of any of the repro steps above. That's much improved from the behavior where the number of runs increases constantly, but still a regression from Sprint 35. Reopening@dangoor as medium priority to address during Sprint 37's further prefs work.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Wednesday Feb 05, 2014 at 21:53 GMT


It looks like the _.isEqual() check is always claiming the settings are unequal, even when switching between two files within the Brackets project.

@core-ai-bot
Copy link
Member Author

Comment by pthiess
Friday Feb 21, 2014 at 17:45 GMT


@peterflynn This seems FBNC

@core-ai-bot
Copy link
Member Author

Comment by ingorichter
Saturday Mar 08, 2014 at 01:40 GMT


@peterflynn@dangoor I don't see it run twice anymore. Closing for now.

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

No branches or pull requests

1 participant