Bug 144055 - Improve perfornamce of service registration
Summary: Improve perfornamce of service registration
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M1   Edit
Assignee: equinox.framework-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2006-05-26 19:27 EDT by Ikuo Yamasaki CLA
Modified: 2006-08-23 15:20 EDT (History)
3 users (show)

See Also:


Attachments
Patch to improve performance of service registration (926 bytes, patch)
2006-05-26 19:29 EDT, Ikuo Yamasaki CLA
no flags Details | Diff
The latest patch of BundleContextImpl (1001 bytes, patch)
2006-06-20 17:28 EDT, Ikuo Yamasaki CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ikuo Yamasaki CLA 2006-05-26 19:27:59 EDT
In BundleContextImpl#registerService(clazzes, service, prop) , 
clazzes are copied into String[] copy as follows:
- - - - - - - - - - -[Current code]- - - - - - - - - - -
/* copy the array so that changes to the original will not affect us. */
String[] copy = new String[clazzes.length];
for (int i = 0; i < clazzes.length; i++) {
	copy[i] = new String(clazzes[i].getBytes());
}
clazzes = copy;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

I wonder if the following implementation is enough.

- - - - - - - - - - -[Revised code]- - - - - - - - - - -
/* copy the array so that changes to the original will not affect us. */
String[] copy = new String[clazzes.length];
for (int i = 0; i < clazzes.length; i++) {
	copy[i] = clazzes[i];
}
clazzes = copy;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
If my understanding is correct, it improves performance of registerService()
because both of String#getByte() and new String() are costly.

Roughly speaking, registering 10,000 services takes
 under a condition (on Windows XP (Pen4 2.5GHz),  JVMOPTIONS=-Xms256M -Xmx256M -Xint):
	[current]   12.94 sec
	[revised]  11.03 sec

# Remember the required time may change according to other stuff
# ( e.g. the number of ServiceListeners registered).
Comment 1 Ikuo Yamasaki CLA 2006-05-26 19:29:03 EDT
Created attachment 42793 [details]
Patch to improve performance of service registration
Comment 2 Oleg Besedin CLA 2006-05-29 11:49:57 EDT
Yes, this would be a better code as well. You might want to go one step further and replace the cycle with:
		System.arraycopy(clazzes, 0, copy, 0, clazzes.length);
Comment 3 BJ Hargrave CLA 2006-05-30 09:19:28 EDT
I think the String "copy" code came from when the code base was working with J9 resource management which used multiple heaps. The goal of the code was to "move" the String objects into the heap of the framework from the heap of the calling bundle. This code should have been isolated into a method call to better document its purpose. Since J9 resource management support is not a stated goal of Equinox at this time, I agree that System.arraycopy is the best choice.
Comment 4 Ikuo Yamasaki CLA 2006-06-20 17:28:05 EDT
Created attachment 44955 [details]
The latest patch of BundleContextImpl

Thanks Oleg and BJ.

I'm sorry I have forgotten to post the latest patch.
Please close the bug when it is committed. >> committers
Comment 5 BJ Hargrave CLA 2006-06-20 23:11:47 EDT
Tom, I will have to assume you meant 3.3M1 since 3.2M1 was a looong time ago :-)

+1 for updated patch.
Comment 6 BJ Hargrave CLA 2006-06-20 23:14:54 EDT
(In reply to comment #0)
>         [current]   12.94 sec
>         [revised]  11.03 sec
> 

Ikuo, Do you have new performance numbers for the updated patch vs. original?
Comment 7 Thomas Watson CLA 2006-06-20 23:40:55 EDT
opps, yes 3.3 M1 ;-)

I released the latest patch to HEAD.  Marking as fixed.  Ikuo, please provide any new performance numbers you have with the latest fix.  Also re-open this bug if you find additional areas where service registration performance could be improved.  Thanks

[contributed patch applied]
Comment 8 Ikuo Yamasaki CLA 2006-06-21 11:10:29 EDT
(In reply to comment #6)
> (In reply to comment #0)
> >         [current]   12.94 sec
> >         [revised]  11.03 sec

I have recently change my test implementation mainly on the way to load multiple classes (and interfaces). While the old one has fragmented bundle which actually contains 10,000 interfaces and 10,000 implementing classes and they are loaded, the new one has no fragmented bundle which contains 1 interface and 1 class and it can dynamically produce specified number of interfaces with different name and its implementing classes. 

In both, service objects are created and stored stored in List, and interface names are stored in String[] before TestRunner.run(). In test(), of which CPU time is measured, these objects and interface name String are retrieved from List and String[]. Although I expected that it would affect the results, it seems it did. In other words, the new one is faster than the old. (I didn't investigate this reason...It might be caused other implementation problem in old one.)

# Therefore, I'm now doing many tests again using new one.

Anyway, one of the results I have now are as follows:
--------
Registering 10,000 services with 3 properties takes (in Interpreted Mode)

[osgi_3.2.0.N20040424-0010.jar + fix of Bug#142385] 9.24 s
[Latest* + fix of Bug#142385] 6.72 s

 *Fixed bugs in Latest include not only Bug#144055 but also Bug#144540.
--------
It will be much faster when using Hotspot, needless to say.

Comment 9 Ikuo Yamasaki CLA 2006-06-21 11:20:02 EDT
(In reply to comment #8)
> I have recently change my test implementation mainly on the way to load
> multiple classes (and interfaces). While the old one has fragmented bundle
> which actually contains 10,000 interfaces and 10,000 implementing classes and
> they are loaded, the new one has no fragmented bundle which contains 1
> interface and 1 class and it can dynamically produce specified number of
> interfaces with different name and its implementing classes. 

Oh, I should have comment who contributed to new excellen original code, which dynamically creates classes and interfaces, for me. It was Oleg. Thank you so much !!
Comment 10 Thomas Watson CLA 2006-08-23 15:20:36 EDT
adding "contributed" keyword to patches contributed by the community.