LiveServer.jl icon indicating copy to clipboard operation
LiveServer.jl copied to clipboard

Only watch what we need to

Open tlienart opened this issue 5 years ago • 4 comments

This is not urgent. I'm just thinking that at the moment, if we trigger lots of requests, lots of files will be watched for changes. This makes sense if all the requests come from new tabs. But otherwise doesn't (e.g. if it's the same tab asking different things we should only really track the file that is currently being watched).

Watching files is very cheap though so not a big deal and even in the case of a huge website, we'd basically have to do hundreds of thousands of requests and modify all these files for it to maybe be a bottleneck.

Suggestion: a doable intermediate step which would feel cleaner is to stop watching files for which there is no associated viewer.

tlienart avatar Apr 05 '19 01:04 tlienart

Suggestion: a doable intermediate step which would feel cleaner is to stop watching files for which there is no associated viewer.

This would be straightforward for HTML files. For all other files, there's IMO two options:

  • The information about the requester (tab / worker) is in the HTTP request. Don't know if it is there anyways (I guess not) or whether we could add it, e.g. by sending a cookie along with the HTML...
  • The server parses the HTML file for any files that are linked to it. Is there a HTML library in Julia doing this already...? Then, we could un-watch also all files that are associated with a HTML file, once that HTML file is not viewed anymore.

asprionj avatar Apr 05 '19 18:04 asprionj

  1. yeah so I think we can implement the simple stuff for HTML files (i.e. check if the corresponding wss is empty and if so remove it from watchefiles )
  2. parsing of HTML can be done with Gumbo.jl potentially.

I think the first one we can do now and could open another issue for a future improvement where we'd do the other one. It's a minor thing and wouldn't affect performances (apart from extreme cases).

tlienart avatar Apr 06 '19 07:04 tlienart

It's not only about performance. One could be working on different HTML files, have them open in different browser windows that he watches at the same time (e.g. both on second screen). He then changes a file that's only used in one of the HTML files, but both update -- this might irritate, since one then usually assumes that the change actually affected both views.

But I agree, for first announcement doing it for HTML files is enough. Gumbo would provide a major piece of the final solution; we could then just traverse the tree and look only at tags that may reference files.

asprionj avatar Apr 06 '19 12:04 asprionj

I think that Gumbo.jl would not be enough, because CSS and ES6 can import recursively, so you would also need parsers for those, which is probably beyond the scope

If the cost of file watching becomes a concern, I would go for #124 :)

fonsp avatar Mar 25 '22 20:03 fonsp