Bug 563771 - [performance] JavaModelManager.getOptions() even in cached case slow
Summary: [performance] JavaModelManager.getOptions() even in cached case slow
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.16   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: performance
Depends on:
Blocks:
 
Reported: 2020-05-31 04:57 EDT by Carsten Hammer CLA
Modified: 2023-01-31 15:07 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carsten Hammer CLA 2020-05-31 04:57:40 EDT
As this code is called every time you run a quickfix and in different other situations it should be as fast as possible. Unfortunately it is creating a complete copy of the preferences using the synchronized Hashtable each time it is called in case of using the cached version.

	public Map<String, String> getOptions() {

		// return cached options if already computed
		Hashtable<String, String> cachedOptions; // use a local variable to avoid race condition (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=256329 )
		if ((cachedOptions = this.optionsCache) != null) {
			return new Hashtable<>(cachedOptions);
		}

The Hashtable.putAll() caused by this adds unnecessary to the processing time.
Comment 1 Jay Arthanareeswaran CLA 2021-01-18 02:44:34 EST
As you can see, the code was added to avoid a race condition. It will be nice to have a solution that addresses both the issues. Do you have a proposal?
Comment 2 Carsten Hammer CLA 2021-01-18 13:00:32 EST
(In reply to Jayaprakash Arthanareeswaran from comment #1)
> As you can see, the code was added to avoid a race condition. It will be
> nice to have a solution that addresses both the issues. Do you have a
> proposal?

I tried to find a specification that describes the architecture regarding the lifecycle of different components in jdt. So far I found nothing.

I don't know how many concurrent different(!) copies of the options can live in the system and which objects there lifecycle is bound to.

It looks like there is no way to run two quickfixes/cleanups at the same time on eclipse. So for this usage this code does not make sense, does it? 

But the build, as described in the referenced bugzilla is affected by this and so it looks like there are some situations where several option-Hashtables can be in the system at the same time with possible (?) different settings. At the moment I wonder in which situations it is needed and in which it is not needed to have a copy.

Maybe we can have another getOptions() method "getOriginalOptions" where you can get the reference to the original datastructure without creating a copy at all? As it is synchronized already even changes were possible. So a caller could choose the right method based on the usage.

Not sure about the right approach..
Comment 3 Eclipse Genie CLA 2023-01-31 15:07:13 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.