Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 324875

Summary: [DataBinding] MapDelegatingValueObservableMap performance problems
Product: [Eclipse Project] Platform Reporter: przemyslaw.pelczar <przemyslaw.pelczar>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: przemyslaw.pelczar
Version: 3.6   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
call tree from profiler
none
call tree - details of MapEntry.getValue none

Description przemyslaw.pelczar@araneo.pl CLA 2010-09-09 13:27:25 EDT
Build Identifier: 20100617-1415

MapDelegatingValueObservableMap uses IObservableMap.containsKey in MapEntry.getValue(), MapEntry.setValue() and put() methods. 

In most cases implementation of containsKey is AbstractMap (because AbstractObservableMap extends AbstractMap). This causes big performance problems, because AbstractMap.containsKey has linear complexity.

Invoking AbstractMap.containsKey should be avoided.

Happily MapEntry.getValue() can be changed to not use this method.
Now is:
public Object getValue() {
 getterCalled();
 if (!masterMap.containsKey(key))
   return null;
 Object masterValue = masterMap.get(key);
 return cache.get(masterValue);
}
Should be:
public Object getValue() {
 getterCalled();

 Object masterValue = masterMap.get(key);
 if (masterValue == null) {
  return null;
 } 
 return cache.get(masterValue);
}

Now adding 1000 elements to WritableList binded to TableViewer using ViewerSupport causes about 500 000 invocations of SetDelegatingValueObservableMap.EntrySet.next()


Reproducible: Always

Steps to Reproduce:
1. Bind TableViewer with few columns to WritableList using ViewerSupport.bind 
2. Try to add more that 1000 elements to WritableList.
Comment 1 przemyslaw.pelczar@araneo.pl CLA 2010-09-09 13:30:52 EDT
Created attachment 178536 [details]
call tree from profiler
Comment 2 przemyslaw.pelczar@araneo.pl CLA 2010-09-09 13:36:41 EDT
Created attachment 178537 [details]
call tree - details of MapEntry.getValue

You can see that in MapDelegatingValueObservableMap.MapEntry.getValue invoking DecoratingObservableMap.containsKey() takes 99% of time because it's delegated to AbstractMap.containsKey(). On the other hand DecoratingObservableMap.get() is fast because its delegated to HashMap.get().
Comment 3 Matthew Hall CLA 2010-09-13 22:02:52 EDT
Sounds like a better solution is to override containsKey to use the HashMap method like get() is doing--no?
Comment 4 przemyslaw.pelczar@araneo.pl CLA 2010-09-14 07:14:56 EDT
I think you are right.

Maybe SetDelegatingValueObservableMap and MapDelegatingValueObservableMap
should override containsKey and use DelegatingCache cache property in it.

I don't know details of implementation. 
But feel that case of null key in maps should be analysed to propose good solution.
Comment 5 Eclipse Webmaster CLA 2019-09-06 16:14:06 EDT
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.
Comment 6 Eclipse Genie CLA 2021-11-12 17:35:12 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.