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

IEP-928: Workspace hangs if project is closed while indexer is running #812

Merged
merged 4 commits into from
Sep 15, 2023

Conversation

sigmaaa
Copy link
Collaborator

@sigmaaa sigmaaa commented Aug 17, 2023

Description

Workspace hangs sometimes if we try to close the project while the indexer is running. Fixed by encapsulating the parsing process into separate Job.

Fixes # (IEP-928)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

  • Build the project in multiple scenarios. Try to close the project during the build or indexer process.

Test Configuration:

  • ESP-IDF Version:
  • OS (Windows,Linux and macOS):

Dependent components impacted by this PR:

  • Build
  • Indexer

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Added Documentation
  • Added Unit Test
  • Verified on all platforms - Windows,Linux and macOS

Summary by CodeRabbit

  • New Feature: Introduced asynchronous parsing of the compile commands file in IDFBuildConfiguration. This change improves the responsiveness of the IDE during build configuration by offloading potentially time-consuming operations to a separate thread.
  • Refactor: Added a new JobGroup instance variable to manage jobs related to the build configuration process, enhancing code organization and job management.
  • Chore: Added new string constants for better message handling and internationalization support.

Copy link
Collaborator Author

@sigmaaa sigmaaa left a comment

Choose a reason for hiding this comment

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

self reviewed

@kolipakakondal kolipakakondal added this to the v2.11.0 milestone Aug 24, 2023
@kolipakakondal
Copy link
Collaborator

Hi @sigmaaa I don't see any issues with approach, let @AndriiFilippov verify multiple projects and scenarios. Can you list down the dependent components which he could check.

@sigmaaa
Copy link
Collaborator Author

sigmaaa commented Aug 28, 2023

Hi @sigmaaa I don't see any issues with approach, let @AndriiFilippov verify multiple projects and scenarios. Can you list down the dependent components which he could check.

Hi Kondal, thanks for the review. I've provided dependent components in the description

@AndriiFilippov
Copy link
Collaborator

AndriiFilippov commented Sep 8, 2023

@sigmaaa hi !

Tested under:
OS - Windows 10 / MacOS
ESP-IDF: v5.1

I don't see any issues when closing the project during indexing, but I notice there is error once I cancel build.
Please, check

Steps:
Create project -> Build project -> cancel build -> error:

image

@kolipakakondal kolipakakondal modified the milestones: v2.11.0, 2.11.1 Sep 14, 2023
@coderabbitai
Copy link

coderabbitai bot commented Sep 15, 2023

Walkthrough

The changes introduced in this pull request primarily focus on improving the performance of the IDFBuildConfiguration class by processing compile commands asynchronously. This is achieved by using Eclipse's Job and JobGroup classes to handle the parsing task in a separate thread, thereby enhancing the responsiveness of the main application.

Changes

File Path Summary
.../idf/core/build/IDFBuildConfiguration.java Introduced asynchronous processing of compile commands using Job and JobGroup. Added error logging for any CoreException during parsing.
.../idf/core/build/Messages.java
.../idf/core/build/messages.properties
Added a new string constant IDFBuildConfiguration_ParseCommand for job description.

🐇💻

In the land where code rabbits hop,

We never let the efficiency drop.

With threads we play, in the async way,

Making sure the app's speed stays at the top! 🚀🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

@sigmaaa sigmaaa changed the title WIP: Workspace hangs if project is closed while indexer is running (IEP-928) IEP-928: Workspace hangs if project is closed while indexer is running Sep 15, 2023
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between 5104b10 and 63beeac commits.
Files selected for processing (1)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java (3 hunks)
Additional comments (Suppressed): 3
bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java (3)
  • 85-97: The new imports org.eclipse.core.runtime.IStatus, org.eclipse.core.runtime.Status, and org.eclipse.core.runtime.jobs.JobGroup are necessary for the changes made in this PR. They are used to create a new JobGroup and handle its status.

  • 130-130: A new JobGroup is created with a limit of one job at a time. This ensures that only one parsing job runs at any given time, which can help prevent potential race conditions or resource contention issues.

private JobGroup jobGroup = new JobGroup("Parsing Job...", 1, 1); //$NON-NLS-1$
  • 974-997: The method processCompileCommandsFile has been modified to run the parsing process asynchronously in a separate job. This change allows the parsing process to be interrupted without causing the entire workspace to hang. However, it's important to ensure that any code that depends on the completion of the parsing process is properly synchronized or otherwise handles the asynchronous nature of this operation.
Job parseJob = new Job("Parse Compile Commands File") //$NON-NLS-1$
{
	protected IStatus run(IProgressMonitor monitor)
	{
		try
		{
			parser.parse(monitor);
		}
		catch (CoreException e)
		{
			Logger.log(e);
		}
		return Status.OK_STATUS;
	}
};
parseJob.setJobGroup(jobGroup);
parseJob.schedule();

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between 63beeac and 0d8373c commits.
Files selected for processing (3)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java (3 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/Messages.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/messages.properties (1 hunks)
Files skipped from review due to trivial changes (2)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/Messages.java
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/messages.properties
Additional comments (Suppressed): 2
bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java (2)
  • 88-94: The new imports IStatus, Status, and JobGroup are introduced to support the creation of a new Job for parsing the compile commands file asynchronously. This is in line with the PR's goal of preventing workspace hang by running the indexer in a separate thread.

  • 130-130: A new JobGroup instance is created. The JobGroup class is part of the Eclipse Jobs API and is used to group related jobs together. Here, it's used to manage the job that parses the compile commands file. Ensure that this JobGroup is properly managed elsewhere in the codebase, i.e., jobs are correctly added and removed when necessary.

Comment on lines 974 to 997
private void processCompileCommandsFile(IConsole console, IProgressMonitor monitor) throws CoreException
{
IFile file = getCompileCommandsJsonFile(monitor);

CompileCommandsJsonParser parser = new CompileCommandsJsonParser(
new ParseRequest(file, new CMakeIndexerInfoConsumer(this::setScannerInformation, getProject()),
CommandLauncherManager.getInstance().getCommandLauncher(this), console));
parser.parse(monitor);
Job parseJob = new Job(Messages.IDFBuildConfiguration_ParseCommand)
{
protected IStatus run(IProgressMonitor monitor)
{
try
{
parser.parse(monitor);
}
catch (CoreException e)
{
Logger.log(e);
}
return Status.OK_STATUS;
}
};
parseJob.setJobGroup(jobGroup);
parseJob.schedule();
}
Copy link

Choose a reason for hiding this comment

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

The processCompileCommandsFile method has been modified to create a new Job for parsing the compile commands file asynchronously. This change is consistent with the PR's goal of preventing workspace hang by running the indexer in a separate thread. However, there's no error handling mechanism if the job fails or doesn't complete successfully. Consider adding an appropriate error handling mechanism.

+                catch (CoreException e)
+                {
+                    Logger.log(e);
+                    return Status.CANCEL_STATUS;
+                }

@kolipakakondal kolipakakondal merged commit 6ff9814 into master Sep 15, 2023
@kolipakakondal kolipakakondal deleted the IEP-928 branch September 15, 2023 09:09
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.

3 participants