Modify

Opened 2 months ago

Last modified 3 weeks ago

#20141 assigned enhancement

ImageProvider: cache rendered SVG images using JCS

Reported by: simon04 Owned by: simon04
Priority: normal Milestone:
Component: Core Version:
Keywords: cache svg jcs performance startup Cc:

Description

On each JOSM start, hundreds of SVG images are rendered to the same sizes as on the previous JOSM start. Caching those rendered images should bring down the startup (a lot).

Early tests look very promising:

-#without cache
-TaggingPresetReaderTest#testReadDefaulPresets 4.176 4.025 3.876 4.110 4.152 [ms]
+#with filled cache
+TaggingPresetReaderTest#testReadDefaulPresets 1.875 1.550 1.742 1.970 1.527 [ms]

Still to be done: extensive testing, cache eviction after changed SVG files, possibly exclude non SVG files from being cached

Attachments (1)

20141.patch (15.9 KB) - added by simon04 2 months ago.

Download all attachments as: .zip

Change History (19)

Changed 2 months ago by simon04

Attachment: 20141.patch added

comment:1 Changed 2 months ago by Klumbumbus

Switching between normal and hidpi should be considered.

comment:2 Changed 2 months ago by Don-vip

Keywords: performance startup added

Nice!

comment:3 Changed 8 weeks ago by simon04

In 17363/josm:

see #20141 - Extract BufferedImageCacheEntry.pngEncoded

comment:4 Changed 8 weeks ago by simon04

In 17364/josm:

see #20141 - ImageProvider: cache rendered SVG images using JCS

This experimental feature is disabled by default. Set the advanced preference jcs.cache.use_image_resource_cache=true to enable. No cache eviction for altered images is implemented at the moment.

comment:5 Changed 8 weeks ago by simon04

Summary: [draft patch] ImageProvider: cache rendered SVG images using JCSImageProvider: cache rendered SVG images using JCS

comment:6 Changed 8 weeks ago by simon04

When enabled via jcs.cache.use_image_resource_cache=true, after the second JOSM restart, the following should be logged to the console:

2020-11-26 22:23:39.156 WARNING: Using experimental disk cache /tmp/.josm/cache/images for ImageResource
2020-11-26 22:23:42.101 INFO: com.kitfox.svg.SVGUniverse@9cf8a28 has loaded 0 SVG images
2020-11-26 22:23:42.103 INFO: ImageResource cache: [Region Name = images
HitCountRam = 1333
HitCountAux = 2907
---------------------------Memory Cache
Put Count = 2907
Hit Count = 1333
Miss Count = 2907
Map Size = 2907
List Size = 2907
---------------------------Block Disk Cache
Is Alive = true
Key Map Size = 8806
Data File Length = 28690377
Block Size Bytes = 1024
Number Of Blocks = 28018
Average Put Size Bytes = 0
Empty Blocks = 0
Purgatory Hits = 0
Purgatory Size = 0
Working = true
Empty = true]

comment:7 Changed 8 weeks ago by GerdP

I see this without changing the preference. Intended?

2020-11-27 10:03:09.128 INFO: com.kitfox.svg.SVGUniverse@3fb3504d has loaded 851 SVG images
2020-11-27 10:03:09.132 INFO: ImageResource cache: [Region Name = images
HitCountRam = 332
HitCountAux = 0
---------------------------Memory Cache
Put Count = 1825
Hit Count = 332
Miss Count = 1825
Map Size = 1825
List Size = 1825]

comment:8 Changed 8 weeks ago by simon04

Yes, it's using JCS as an in-memory-cache (as replacement for the previously used ConcurrentHashMap).

comment:9 Changed 8 weeks ago by skyper

With empty preferences, I get following warning on the console when opening Preferences -> Tagging Presets:

WARNING: row index is bigger than sorter's row count. Most likely this is a wrong sorter usage.

Adding a preset with external icons (e.g. "Navigation sign for hospital") spawns the console with:

WARNING: CSS parser not implemented yet

comment:10 Changed 8 weeks ago by gaben

Huh, something happened to my JOSM. It freezes at startup, clicking sometimes takes seconds to register, and while doing this the CPU usage is around 10% :/
r17360 works fine, r17364 not.

URL:https://josm.openstreetmap.de/svn/trunk
Repository:UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
Last:Changed Date: 2020-11-26 22:24:27 +0100 (Thu, 26 Nov 2020)
Build-Date:2020-11-27 02:30:53
Revision:17364
Relative:URL: ^/trunk

Identification: JOSM/1.5 (17364 hu) Windows 10 64-Bit
OS Build number: Windows 10 Pro for Workstations 2004 (19041)
Memory Usage: 1000 MB / 1820 MB (560 MB allocated, but free)
Java version: 1.8.0_271-b09, Oracle Corporation, Java HotSpot(TM) 64-Bit Server VM
Look and Feel: com.sun.java.swing.plaf.windows.WindowsLookAndFeel
Screen: \Display0 1920×1200 (scaling 1,00×1,00)
Maximum Screen Size: 1920×1200
Best cursor sizes: 16×16→32×32, 32×32→32×32

comment:11 Changed 8 weeks ago by GerdP

I can reproduce long delays with r17367 and no change in the preference, e.g. when pressing Ctrl+N to create a first layer. VisualVM shows org.apache.commons.jcs3.engine.memory.AbstractDoubleLinkedListMemoryCache.verifyCache() as problem in many different init() routines.

comment:12 Changed 8 weeks ago by GerdP

I've now tried with jcs.cache.use_image_resource_cache=true, same problems. Please improve or revert for now, JOSM is unusable with these changes.

comment:13 Changed 8 weeks ago by gaben

The startup process freezes for 7s while loading imagery.
After fresh JOSM start, the download action (Ctrl+Shift+Down) takes about 9 seconds to show the download dialog. The second time it's instantaneous.

comment:14 Changed 8 weeks ago by simon04

In 17369/josm:

see #20141 - Revert "ImageProvider: cache rendered SVG images using JCS"

comment:15 Changed 8 weeks ago by GerdP

I've tried r17367 with a clean home java -jar -Djosm.home=c:\temp\josm_dev dist\josm-custom.jar and that doesn't show the long delays. Let me know if you need more info in case you cannot reproduce the delays.


comment:16 Changed 8 weeks ago by GerdP

When I uninstall apache-commons.jar I see no delays, it is required by opendata plugin.

comment:17 Changed 8 weeks ago by simon04

Longing for a weekend without troubles. Perhaps, I'll pick up this idea eventually in the future.

comment:18 Changed 3 weeks ago by simon04

Milestone: 20.12

Modify Ticket

Change Properties
Set your email in Preferences
Action
as assigned The owner will remain simon04.
as The resolution will be set.
to The owner will be changed from simon04 to the specified user.
The owner will change to simon04
as duplicate The resolution will be set to duplicate.The specified ticket will be cross-referenced with this ticket

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.