Bug 72258 - [model] Should be able to dynamicaly set the size of Java model cache
Summary: [model] Should be able to dynamicaly set the size of Java model cache
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 75946 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-08-19 09:35 EDT by Jerome Lanneluc CLA
Modified: 2005-03-31 11:27 EST (History)
4 users (show)

See Also:


Attachments
Log of slowdown (578.88 KB, application/octet-stream)
2005-02-18 13:48 EST, Matthew Conway CLA
no flags Details
Patch to apply on org.elipse.jdt.core v_538 (2.20 KB, patch)
2005-02-23 10:52 EST, Jerome Lanneluc CLA
no flags Details | Diff
Trace of slowdown after applying patch (554.12 KB, application/octet-stream)
2005-02-23 11:17 EST, Matthew Conway CLA
no flags Details
Patch to apply on org.elipse.jdt.core v_538 (6.21 KB, patch)
2005-02-23 13:16 EST, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jerome Lanneluc CLA 2004-08-19 09:35:24 EDT
I20040812

The maximum size of the Java model caches is currently static. User should be 
able to dynamicaly update it so that he/she can work with larger/smaller 
workspaces.
Comment 1 Noel Grandin CLA 2004-08-19 10:01:06 EDT
Ideally, it should scale without me explicitly setting it. I can think of 2 
strategies

(a) memory sensitive. Jerome has indicated that using WeakHashMap won't work 
(not sure why). Also, my own experiences with WeakHashMap suggest that the VM 
is not very smart about GC'ing weakly linked stuff. Mind you, that was with 
JDK1.3. Things might have improved since then.

(b) Scale it based on the number of java files in the currently opened 
workspace, with perhaps some kind of limit based on the currently configurated 
memory available to the VM.
Something like 
int lruSize = Math.min(100, Math.min
(noOfFiles/3,maxMemMegabytesConfigured/128*1000)).
where the numbers I've inserted are a complete guess, and the additional min() 
call provides a lower bound for newly created workspaces.


Comment 2 Jerome Lanneluc CLA 2004-11-16 09:23:51 EST
Yes automaticaly detecting the cache size would be ideal. But
a) the WeakHashMap behavior is weakly (<g>) specified (no guaranty that elements
in the map will be garbagged collected in the near future) so we cannot rely on this
b) this would mean traversing the whole workspace tree which can be costly

I still think that having this limit as an option would be better.
Comment 3 Dani Megert CLA 2004-11-16 09:30:35 EST
*** Bug 75946 has been marked as a duplicate of this bug. ***
Comment 4 Matthew Conway CLA 2004-11-16 10:54:41 EST
If I wanted to hardcode in a larger cache size, where would I need to edit?
Comment 5 Jerome Lanneluc CLA 2004-11-16 10:57:41 EST
That would be org.eclipse.jdt.internal.core.JavaModelCache#CACHE_RATIO.
Comment 6 Matthew Conway CLA 2004-11-16 11:23:48 EST
Great, thanks!
Is this only used in that class?  i.e. can I get away with just compiling
org.eclipse.jdt.core (public static final var, so compile time resolution)?
Comment 7 Jerome Lanneluc CLA 2004-11-16 11:27:49 EST
Yes this static field is used in this class only. It could be private.
Comment 8 Philipe Mulet CLA 2004-11-16 12:59:37 EST
Alternatively, we could investigate a different caching policy: never close
indidividual roots, but rely on project getting closed at once.
Similar to not closing packages, but rather roots as wholes. This may require to
transfer some information from project element infos to per-project infos.
Comment 9 Matthew Conway CLA 2004-11-16 14:45:19 EST
Just an FYI/confirmation - I doubled my CACHE_RATIO to 40 and my problems from
bug 75946 went away.

Comment 10 Jerome Lanneluc CLA 2004-11-24 04:50:13 EST
Thanks for confirming this was the problem Matthew.

Changed the JavaModelCache to increase its maximum size so that the children of
an element always fit in the cache. It resets its limit to the default size when
the element is closed. See JavaModelCache#ensureSpaceLimit(Map) and
resetSpaceLimit(IJavaElement)
Comment 11 Frederic Fusier CLA 2004-12-14 13:39:33 EST
Verified for 3.1 M4 using build I200412140800.
Please not that constant is now called BASE_VALUE in JavaModelCache.
Comment 12 Matthew Conway CLA 2004-12-21 13:35:36 EST
This is still a source of major slowdown for me with a very large project in
eclipse 3.1M4.

If I edit JavaModelCache and double BASE_VALUE to 40, the slowdown goes away, so
I suspect that the dynamic cache size adjustment is not taking place.
Comment 13 Jerome Lanneluc CLA 2005-01-03 05:22:45 EST
Matthew, could you please enable the Java model tracing as follows:

1. Create a .options file with the following content:
# Turn on debug tracing for org.eclipse.jdt.core plugin
org.eclipse.jdt.core/debug=true
# Reports Java model elements opening/closing
org.eclipse.jdt.core/debug/javamodel=false

2. Start Eclipse with -debug <path to the .options file> -vm <path to
jre>\bin\java.exe

3. Ensure that the DOS console that is opened has a buffer size set to 9999

4. Copy/paste the trace in a .txt file and attach it to this bug report
Comment 14 Jerome Lanneluc CLA 2005-01-04 06:03:38 EST
Of course in comment #13 I meant:
org.eclipse.jdt.core/debug/javamodel=true
Comment 15 Jerome Lanneluc CLA 2005-02-14 10:42:37 EST
Please reopen when you have the trace.
Comment 16 Matthew Conway CLA 2005-02-18 13:48:06 EST
Here you go - Sorry it took so long, been busy at work and its time consuming
for for me to retrace as I had to get/install an unmodified version of eclipse
without my edit of JavaModelCache.  I also added the following line to .options
as that was neccessary for bug 75946 :
org.eclipse.jdt.core/debug/resolution=true

I opened eclipse, ctrl-tabbed between two different source windows, Select all
(ctrl-a), Copy (ctrl-c), left click, and it usually takes about 10 secs before
eclipse clears the selection.  Second time in the same file is quick, but when I
switch to another source file the slowdown reoccurs.  The slowdown goes away
when I double JavaModelCache.BASE_VALUE to 40 (which I need to do to resume real
work =)

Comment 17 Matthew Conway CLA 2005-02-18 13:48:53 EST
Created attachment 18104 [details]
Log of slowdown
Comment 18 Matthew Conway CLA 2005-02-18 13:50:51 EST
Won't let me reopen the bug, so I'll let you do it ;)
Also, testing this with eclipse I20050218-1200 (M5 hopeful)

Comment 19 Philipe Mulet CLA 2005-02-18 16:09:37 EST
The JavaModel cache is now able to resize dynamically, and this was changed a
while ago (2-3 months).
Are you still observing the issue in M5 ?
Comment 20 Matthew Conway CLA 2005-02-18 16:33:43 EST
Yes, still observing the problem in M5
The dynamic resize doesn't seem to work - or at least does not seem to be effective.
If I edit the size of the JavaModel cache manually, the problem goes away, but
hacking source code is not a good workaround for most people =)

Comment 21 Philipe Mulet CLA 2005-02-19 10:36:29 EST
reopening
Comment 22 Matthew Conway CLA 2005-02-22 12:20:10 EST
One more observation - the method I use for reproducing the slowdown as
described above only works if the two sourcefiles I switch between belong to
different source folders in the same project.
Comment 23 Jerome Lanneluc CLA 2005-02-23 10:52:54 EST
Created attachment 18237 [details]
Patch to apply on org.elipse.jdt.core v_538

Thanks for your efforts in helping tracking this down. I was able to reproduce
by creating a Java project with 300 source folders.

The problem is not really with the default size of the Java model cache, but
with the fact that the root cache of the project is cleared too often. I also
added another optimization when querying the kind of a root to avoid populating
the cache.

Could you please try the attached patch and let me know if this fixes your
problem ?
Comment 24 Matthew Conway CLA 2005-02-23 11:11:17 EST
Applied the patch, but it did not help.

Comment 25 Matthew Conway CLA 2005-02-23 11:17:13 EST
Created attachment 18239 [details]
Trace of slowdown after applying patch

Ran through the same scenario I used for the previous trace, but did it using a
patched org.eclipse.jdt.core v_538 on 3.1M5a
Comment 26 Jerome Lanneluc CLA 2005-02-23 11:55:15 EST
My test case was too simple. With cus refering to each other, I see the problem
too. I'm investigating.
Comment 27 Jerome Lanneluc CLA 2005-02-23 13:16:56 EST
Created attachment 18249 [details]
Patch to apply on org.elipse.jdt.core v_538

I think I have it now. Could you please try with this new patch ?
Comment 28 Matthew Conway CLA 2005-02-23 13:56:35 EST
Excellent!  That seemed to do the trick.
Thanks!
Comment 29 Jerome Lanneluc CLA 2005-02-24 05:09:59 EST
Thanks for confirming this works.
Released patch into HEAD.
Added regression test OverflowingCacheTests#testBigNumberOfRoots()
Comment 30 David Audel CLA 2005-03-31 11:27:44 EST
Verified in I20050330-0500