-
Notifications
You must be signed in to change notification settings - Fork 13
[#412] cache enablement for URI #415
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
So, only restart will clear the cache and this is desired, correct?
Yes. But I would like to add a clear mechanism which would be triggered when the |
Please fill free to merge both when needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that the PropertyTester's test method is called a lot so speeding that up has great value. Here are some comments.
- The title of this PR and commit need cash -> cache
- PropertyTester must be stateless, see javadoc - the new cache is kindof stateful, or rather you may end up with multiple caches the way it is done now.
- The cache is accessed from multiple threads, so some consideration to concurrency is needed.
- Should this be doing LRU style so that items don't stay and this grows forever. CDT has one org.eclipse.cdt.internal.core.LRUCache<K, V>
- As it happens @ramele1907 is looking at some concurrency + LRU cache issues in Synchronize the access to LRUCache cdt#978
- That code in CDT deals with a similar problem you have in LSP4E which is URI -> IReource caches. See eclipse-cdt/cdt@9e7b5be for when that was introduced
- I think the discussions in [#1207] cache IResource in EnablementTester eclipse-lsp4e/lsp4e#1208 are relevant to this PR too so I am cross referencing them here
- Cache invalidation may be needed, see longer comment below
Cache invalidation
My concern with this change is rather a corner case, but that there should be logic to clear the cache as some of the tests can return different results. For example you are checking content types and caching that result. In that case you need to add a listener org.eclipse.core.runtime.content.IContentTypeManager.addContentTypeChangeListener(IContentTypeChangeListener) so that you find out about content type changes.
A simple manual test:
- Create a file called "file.jonah"
- Double-click to open, will not be opened in CDT LSP because it isn't a C/C++ file
- Add jonah as a C file extension in preferences:
- Make sure the file now opens as an LSP editor
Doing a addContentTypeChangeListener will be sufficient to invalidate cache for content type changes, similar mechanism may be needed for other cases.
I mentioned LRU above, but time based caching may also be useful.
Thank you @jonahgraham for the good input I'll consider it! |
Ok, this is more a reminder to me:
A resource shall be removed form the cache if it's getting closed in the editor. The cache shall be implemented as FIFO buffer with n entries which considers concurrency and stateless aspects |
e1cb948
to
4d560b3
Compare
not needed anymore since we now remove files if they are getting closed.
So, I think this should work now. Please review. |
Note: |
when one buffer reaches buffer limit
for example from C/C++ stdlib
Sorry, I think this is it. I found some issue during tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have only been able to review on my phone. I can try running it up next week.
Optional.ofNullable(LSPEclipseUtils.toUri(editor.getEditorInput())).ifPresent(uri -> { | ||
var data = cache.get(uri); | ||
if (data != null) { | ||
if (--data.counter <= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a small comment that counter
field should only be accesed from SWT main thread is appropriate here. AFAICT that is how this is implemented as I assume partOpened and partClosed are only called on SWT main thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the partOpen and partClosed methods are called in the main thread
if (--data.counter <= 0) { | ||
cache.remove(uri); | ||
} else { | ||
cache.put(uri, data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line seems to be a no-op, just putting back in the same instance as you extracted on line 146
if (data != null) { | ||
data.enable = true; | ||
++data.counter; | ||
cache.put(uri, data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No-op line?
This change looks good and I think you have well resolved all my previous issues. |
this would lead to descreased performance because the cache is only filled on file open. All opened files would not be cached if the cache is getting cleared.
- all opened files in the LSP based editor are added to cache again if the content is still a C/C++ content. - clean up API of CLanguageServerEnableCache
Use case: Several C/C++ files are opened in LSP based editor -> restart -> Change C/C++ content type -> select file -> partOpened gets called and increases the opened counter ==> Fault: counter will be increased twice (1st time during restore after content type change, 2nd time on selection (file was not yet selected after restart)
bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorMetadata.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorOptions.java
Outdated
Show resolved
Hide resolved
thanks! |
because they are distinctable and solves the clear-cache-problem when the same URI is opened in several windows. Otherwise we do not know if the URI is still opened somewhere and the cache shouldn't be removed for this URI.
I don't know. The unit tests run on my machine successfully but not on the server: |
@ghentschke If I run CLanguageServerEnableCacheTest in my IDE with default plug-ins enabled it passes, but if I try to simulate what Tycho does and only enable the plug-ins in the dependency tree it fails locally for me like it does on the build machine. See https://github.com/eclipse-cdt/cdt/blob/main/TESTING.md#using-limited-sets-of-plug-ins-in-tests for some guidance on how to setup the test in the IDE. Specifically for this case I did this:
For 7 above here is a screenshot with "Only show selected" checked NOTE: CDT mostly avoids using fragments for tests. One of the advantages of this is that the test bundles are full-fledged bundles. The flow in the CDT instructions (highlight link) don't work for CDT LSP because CDT LSP uses a fragment and can't be selected. This is why I gave explicit instructions above. So what to do about the difference. There is probably some implicit dependency the test has for correct behavior. If so, you need to tell tycho about it or remove that dependency. Here is an example in CDT. |
I raised eclipse-pde/eclipse.pde#1607 to add the ability to PDE to create the kind of launch that can include the fragment. |
@jonahgraham Thanks for the hints!!! Now it works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ghentschke I hope my comment here makes sense - the combination of adapter factories, handling and auto-downloading of URIs and EGit registering something globally (that arguably it shouldn't) makes this a bit of a mess.
bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/util/LspUtils.java
Outdated
Show resolved
Hide resolved
org.eclipse.egit.ui, | ||
org.eclipse.egit.core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See other comment - please remove this dependency
…ils.java Co-authored-by: Jonah Graham <[email protected]>
- remove obsolete egit dependency in test fragment.
@jonahgraham any objections left? |
Thank you @jonahgraham and @ruspl-afed ! |
part of #412
fixes #231