Modify

Opened 4 years ago

Last modified 17 months ago

#20141 assigned enhancement

[patch] 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 (2)

20141.patch (15.9 KB ) - added by simon04 4 years ago.
20141.2.patch (21.4 KB ) - added by taylor.smock 17 months ago.

Download all attachments as: .zip

Change History (23)

by simon04, 4 years ago

Attachment: 20141.patch added

comment:1 by Klumbumbus, 4 years ago

Switching between normal and hidpi should be considered.

comment:2 by Don-vip, 4 years ago

Keywords: performance startup added

Nice!

comment:3 by simon04, 4 years ago

In 17363/josm:

see #20141 - Extract BufferedImageCacheEntry.pngEncoded

comment:4 by simon04, 4 years ago

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 by simon04, 4 years ago

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

comment:6 by simon04, 4 years ago

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 by GerdP, 4 years ago

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 by simon04, 4 years ago

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

comment:9 by skyper, 4 years ago

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 by gaben, 4 years ago

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 by GerdP, 4 years ago

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 by GerdP, 4 years ago

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 by gaben, 4 years ago

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 by simon04, 4 years ago

In 17369/josm:

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

comment:15 by GerdP, 4 years ago

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 by GerdP, 4 years ago

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

comment:17 by simon04, 4 years ago

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

comment:18 by simon04, 4 years ago

Milestone: 20.12

by taylor.smock, 17 months ago

Attachment: 20141.2.patch added

comment:19 by gaben, 17 months ago

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

comment:20 by taylor.smock, 17 months ago

I've updated the patch that was reverted in r17369 for testing purposes.

Notes: It doesn't seem to be as efficient as it could be -- I would expect that there would be no cache misses on the second startup. There were. Even if it isn't perfect, it did decrease memory allocations by 14.5% and CPU cycles by 18.5%. JVM methods decreased by 13.6% and JOSM started ~3s faster.

This patch is not ready (I have not looked into the problems found by GerdP and gaben).

EDIT: It looks like it might take multiple runs for images to get cached.

Last edited 17 months ago by taylor.smock (previous) (diff)

comment:21 by gaben, 17 months ago

See #16733 for offline svg compiling.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as assigned The owner will remain simon04.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from simon04 to the specified user. Next status will be 'new'.
Next status will be 'needinfo'. The owner will be changed from simon04 to simon04.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. 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.