Bug 26926 - TextViewer - Switch to non-default encoding takes a minute
Summary: TextViewer - Switch to non-default encoding takes a minute
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Kai-Uwe Maetzel CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2002-11-22 05:04 EST by Dani Megert CLA
Modified: 2002-12-04 09:44 EST (History)
2 users (show)

See Also:


Attachments
Profiler output 1/2 (75.19 KB, text/html)
2002-11-28 07:03 EST, Dani Megert CLA
no flags Details
Profiler output 2/2 (75.44 KB, text/html)
2002-11-28 07:04 EST, Dani Megert CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2002-11-22 05:04:45 EST
Build 20021119

1. Open PackageExplorerPart.java (with default encoding)
2. Edit -> Encoding -> UTF-16
==> takes more than a minute, CPU is at 100%

3. Enter some text
4. Select Edit -> Revert
==> takes more than minute, CPU is at 100%
Comment 1 Dani Megert CLA 2002-11-28 07:01:27 EST
The profiler shows that StyledText's calls to the OS for bidi rendering use the
CPU - see attached log (investigated with build I20021127).

1. start empty workspace
2. create simple project
3. create simple file called PackageExplorerPart.java
   - leave it open in the editor (per default it's the Java editor)
4. in another workspace checkout PackageExplorerPart.java () from CVS (JDT UI
plug-in), open it and copy the whole text
5. paste the text into the empty PackageExplorerPart.java
6. Save
7. Set caret to the end of the text
8. Edit -> Encoding -> UTF-16 (big endian)

NOTES:
1) UTF-16 alone does not show the problem, but UTF-16 (big endian) and UTF-16
(little endian) do.
2) It matters where the caret is: if its at position 0 then its not that slow
but the more you increase the position the slower it gets. For the attatched
trace I set the caret to the end of the text - it took minutes.
3) The report does not cover the full operation from above scenario - I stopped
after 10 minutes because the operation was still going on
4) On my machine I have bidi and dbcs support installed.

The profiler shows that StyledText's calls to the OS for bidi rendering use the
CPU - see attached log.
Comment 2 Dani Megert CLA 2002-11-28 07:03:07 EST
Created attachment 2556 [details]
Profiler output 1/2
Comment 3 Dani Megert CLA 2002-11-28 07:04:47 EST
Created attachment 2557 [details]
Profiler output 2/2
Comment 4 Christophe Cornu CLA 2002-11-28 09:33:56 EST
Daniel, what was your default encoding? (in step 1 of your first comment).

Observed the same problem when starting with my default locale cp1252 on 
WinXP - had to kill Eclipse after a few minutes.

Lynne to investigate and advise.

Comment 5 Dani Megert CLA 2002-11-28 09:52:17 EST
My default was also cp1252.
If you set the cursor at the beginning (e.g. second line) you will not need to
kill it ;-)
Comment 6 Lynne Kues CLA 2002-12-03 15:04:28 EST
The problem is that the TextViewer is executing its method getWidthInPixels 
with the contents of the text viewer up to the caret and the call is being made 
twice.  In my case, my document is approximately 14000 characters long.  
Putting the caret at the end of the document leads to 28000 calls to StyledText 
>> getLocationAtOffset (one for each character up to the cursor).

Platform calls to measure text are costly and even more so in the bidi case.  
As you place the caret further down in the document, more text is being 
measured, so this is why it was faster when the caret is placed at the 
beginning of the document.    

Moving to TextViewer.  This is not a StyledText issue.  The TextViewer should 
be smarter about measuring text, though I'm not sure why it is even measuring 
text in the first place.  Fixing this problem will speed up the TextViewer in 
general.
Comment 7 Dani Megert CLA 2002-12-04 09:44:10 EST
Fixed by Kai.
Available in builds > 20021204