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

Implement caching for diff in IntelliJ extension #4753

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ferenci84
Copy link
Contributor

@ferenci84 ferenci84 commented Mar 21, 2025

Description

Caches diff for IntelliJ plugin.

Issue: #4130

Checklist

  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Testing instructions

Use autocomplete in a testing environment under IntelliJ.

IDE Logs tab contains logs about caching:
Screenshot 2025-03-21 at 15 25 42

@ferenci84 ferenci84 requested a review from a team as a code owner March 21, 2025 14:24
@ferenci84 ferenci84 requested review from Patrick-Erichsen and removed request for a team March 21, 2025 14:24
Copy link

netlify bot commented Mar 21, 2025

Deploy Preview for continuedev canceled.

Name Link
🔨 Latest commit 19d6246
🔍 Latest deploy log https://app.netlify.com/sites/continuedev/deploys/67dee4f5275b9e0008fadcfb

Copy link
Collaborator

@Patrick-Erichsen Patrick-Erichsen left a comment

Choose a reason for hiding this comment

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

Hey @ferenci84 , thanks for the additional contribution here!

I'm curious what prompted you to build this out - have you been having issues with the current getDiff? Looking at the code I can see how it would be quite expensive to compute, so a cache here makes sense to me, but just curious if you've been having issues or if it's just a part of the codebase you noticed could be improved.

Regarding my review - I was a bit nitpicky here because this feels like an important part of the codebase to get right, so I think if we want to build out a cache for diffs we should make sure it's rock solid since we're introducing more complexity.

* Updates the timestamp when a file is saved
*/
override fun updateLastFileSaveTimestamp() {
println("Updating last file save timestamp")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
println("Updating last file save timestamp")

I think this will be too noisy of a log

@@ -110,6 +129,16 @@ class IntelliJIDE(
}

override suspend fun getDiff(includeUnstaged: Boolean): List<String> {
println("Getting diff, cache timestamp: ${diffCache?.timestamp}, current timestamp: $lastFileSaveTimestamp")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
println("Getting diff, cache timestamp: ${diffCache?.timestamp}, current timestamp: $lastFileSaveTimestamp")

Similarly, I think this will be too noisy


// Check if we have a valid cache entry
if (diffCache != null && diffCache!!.timestamp == lastFileSaveTimestamp) {
println("Using cached diff")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
println("Using cached diff")

}

// If no cache hit, compute the diff
println("Computing fresh diff")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
println("Computing fresh diff")

@ferenci84
Copy link
Contributor Author

Hi @Patrick-Erichsen, Thank you for thoughtful review. I have made the requested modifications.

Regarding cache size, this stores only the very last value, so the size is already limited, it's not a full-featured cache, anything more complicated would be overkill for this case.

I'm curious what prompted you to build this out - have you been having issues with the current getDiff? Looking at the code I can see how it would be quite expensive to compute, so a cache here makes sense to me, but just curious if you've been having issues or if it's just a part of the codebase you noticed could be improved.

I made a resolution of issue #4130 for VS code with a default 10s cache for platforms with no implementation, and recently I'd been getting a message every few days that the problem presents (too many git processes are started at the same time), and it's so serious that they cannot use the extension at all. This is not something that comes up with simple test scenarios, but in real-world case where you have lot of staging modifications and potentially large diff (think complied js files that are technically not binary, but are very large and diff computation is slow).

@ferenci84 ferenci84 force-pushed the intellij_cache_diff branch from 249b61e to af26eae Compare March 22, 2025 06:51
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

Successfully merging this pull request may close these issues.

2 participants