Bug 82914 - [KeyBindings] performance: Too many MissingResourceException from NativeKeyFormatter
Summary: [KeyBindings] performance: Too many MissingResourceException from NativeKeyFo...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P1 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Douglas Pollock CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2005-01-15 12:53 EST by Andrey Loskutov CLA
Modified: 2005-05-11 14:56 EDT (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 Andrey Loskutov CLA 2005-01-15 12:53:41 EST
I'm trying to debug Eclipse plugins in Eclipse 3.1, and I have *tons* of 
MissingResourceException from NativeKeyFormatter (I have added exception 
breakpoint on RuntimeException).
Here is the stack trace from debugger: 

Thread [main] (Suspended (exception MissingResourceException))
	PropertyResourceBundle(ResourceBundle).getObject(String) line: 326
	PropertyResourceBundle(ResourceBundle).getString(String) line: 286
	Util.translateString(ResourceBundle, String, String, boolean, boolean) line: 
453
	NativeKeyFormatter(AbstractKeyFormatter).format(Key) line: 66
	NativeKeyFormatter.format(Key) line: 123
	NativeKeyFormatter(AbstractKeyFormatter).format(KeyStroke) line: 110
	NativeKeyFormatter(AbstractKeyFormatter).format(KeySequence) line: 79
	KeySequence.format() line: 272
	CommandCallback.getAcceleratorText(String) line: 170
	ActionContributionItem.update(String) line: 792
	SubContributionItem.update(String) line: 160
	MenuManager.update(String) line: 680
	MenuManager.update(String) line: 680
	Workbench.updateActiveWorkbenchWindowMenuManager(boolean) line: 2070
	Workbench.access$0(Workbench, boolean) line: 2058
	Workbench$3.windowActivated(IWorkbenchWindow) line: 2042
	Workbench$8.run() line: 406
	InternalPlatform.run(ISafeRunnable) line: 1007
	Platform.run(ISafeRunnable) line: 747
	Workbench.fireWindowActivated(IWorkbenchWindow) line: 404
	WorkbenchWindow$5.shellActivated(ShellEvent) line: 2215
	TypedListener.handleEvent(Event) line: 163
	EventTable.sendEvent(Event) line: 82
	Shell(Widget).sendEvent(Event) line: 833
	Shell(Widget).sendEvent(int, Event, boolean) line: 857
	Shell(Widget).sendEvent(int) line: 838
	Shell(Decorations).WM_ACTIVATE(int, int) line: 1507
	Shell.WM_ACTIVATE(int, int) line: 1444
	Shell(Control).windowProc(int, int, int, int) line: 3016
	Shell(Decorations).windowProc(int, int, int, int) line: 1483
	Display.windowProc(int, int, int, int) line: 3376
	OS.PeekMessageW(MSG, int, int, int, int) line: not available [native method]
	OS.PeekMessage(MSG, int, int, int, int) line: 1999
	Display.readAndDispatch() line: 2449
	Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 1577
	Workbench.runUI() line: 1543
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 287
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 144
	IDEApplication.run(Object) line: 102
	PlatformActivator$1.run(Object) line: 220
	EclipseStarter.run(Object) line: 274
	EclipseStarter.run(String[], Runnable) line: 129
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available 
[native method]
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
	Method.invoke(Object, Object...) line: 585
	Main.basicRun(String[]) line: 255
	Main.run(String[]) line: 811
	Main.main(String[]) line: 795

The problem is, that NativeKeyFormatter tries to get internationalized keys for 
all possible key strokes for many menu entries in Eclipse, and for most of them 
(like ',', 'A', 'B', 'C', ... , 'Z') there is no translation in resource bundle.

Ergo => ResourceBundle create and throws every time a new 
MissingResourceException, which will be ignored by NativeKeyFormatter and this 
happens *every time* on *every* mouse/key move in Eclipse. 

Two reasons to fix this behavoir:
1) Create and throw an exception is costly - it takes time and memory. In this 
case, this happens on *every* typeEvent and is therefore *very* bad for Eclipse 
editor performance.
2) I can't filter out *my* RuntimeExceptions because there are simply too many 
MissingResourceException from AbstractKeyFormatter.

I would propose simply remember missing keys in internal cache of org.eclipse.
ui.internal.util.Util class (or wherever it could be stored) and do not ask 
PropertyResourceBundle any time for key, if this key is already in 
"MissingKeysCache".

eclipse.buildId=I200411050810
java.runtime.version=1.5.0_01-b08
osgi.nl=de_DE
osgi.os=win32
Comment 1 Andrey Loskutov CLA 2005-01-15 13:18:48 EST
As a temporary workaround I have added this to 
workbench.jar\org\eclipse\ui\internal\keys\AbstractKeyFormatter.properties:
a=a
b=b
c=c
d=d
e=e
f=f
g=g
h=h
i=i
j=j
k=k
l=l
m=m
n=n
o=o
p=p
q=q
r=r
s=s
t=t
u=u
v=v
w=w
x=x
y=y
z=z
,=,
A=A
B=B
C=C
D=D
E=E
F=F
G=G
H=H
I=I
J=J
K=K
L=L
M=M
N=N
O=O
P=P
Q=Q
R=R
S=S
T=T
U=U
V=V
W=W
X=X
Y=Y
Z=Z
0=0
1=1
2=2
3=3
4=4
5=5
6=6
7=7
8=8
9=9
/=/
\\=\\
.=.
-=-
_=_

This help me currently to get rid of silly MissingResourceException's.
Comment 2 Douglas Pollock CLA 2005-01-17 12:16:30 EST
Yes, I've known about this for a while, but just haven't had the time to look 
for a good solution. 
Comment 3 Tod Creasey CLA 2005-03-07 11:57:29 EST
Adding my name to the cc list as we are now tracking performance issues more
closely. Please remove the performance keyword if this is not a performance bug.
Comment 4 Douglas Pollock CLA 2005-04-07 09:39:44 EDT
Investigate for 3.1 M7.
Comment 5 Douglas Pollock CLA 2005-04-18 15:37:58 EDT
I'm using a clever (perhaps too clever) trick to handle this situation.  This
might cause us problems later on with 4-byte character languages, but we'll wait
to see.  At this point, fixing this without tinkering with API would be painful.

The trick is this.  If the "name" string is only one character, don't do a
look-up.  All special keys have names that are two or more characters.

Some timings I did suggest that this should lead to noticeable performance
improvement on closing editors.  It should also affect any of the activation
changes in the workbench: opening/closing/switching parts/perspectives/windows.
Comment 6 Douglas Pollock CLA 2005-05-11 14:56:33 EDT
There only just over 100 MissingResourceExceptions created on start-up.  None of
these are produced by the NativeKeyFormatter.