-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize MimePath#validate by first querying the MimePath cache before attempting to parse #3976
Optimize MimePath#validate by first querying the MimePath cache before attempting to parse #3976
Conversation
I was annoyed by the performance of scanning of JS sources and I had the feeling, that the performance dropped after the changes from #3516. While I'm still not sure whether performance suffered, I noticed a strange thing in the profile (npss in the file): A significant potion of the total time is spend in A totally unscientific test looks promising: Baseline
Patched:
There could be pathological cases (the ones where @dbalek what do you think? |
@@ -131,7 +131,7 @@ public final class MimePath { | |||
"video" //NOI18N | |||
)); | |||
|
|||
private static final Map<String,Reference<MimePath>> string2mimePath = new HashMap<String,Reference<MimePath>>(); | |||
private static final Map<String,Reference<MimePath>> string2mimePath = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synchronization looks ok to me, but what about Collections.synchronizedMap
and forgetting about those synchronized
blocks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid point, I switched to ConcurrentHashMap
which should be better than the suggested synchronizedMap
(finer Locking). What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthiasblaesing ConcurrentHashMap
is more performant. I assume we won't be storying nulls as values though.
@@ -278,6 +278,12 @@ public static boolean validate(CharSequence type, CharSequence subtype) { | |||
* @since 1.7 | |||
*/ | |||
public static boolean validate(CharSequence path) { | |||
String pathString = path == null ? null : path.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't parseImpl()
immediately blow up with null
anyway? Could simplify and let it throw NPE here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, not keys nor values (Weak References) seem to be null. ConcurrentHashMap will do fine!
…e attempting to parse For the changes regarding the switch from a synchronized access to a HashMap to a ConcurrentHashMap: The existing synchronisation only protected the get and set operations on the map and not some secondary functionality (iteration for example). Using a ConcurrentHashMap should thus improve performance and not change the semantics.
5831665
to
7775ab1
Compare
@vieiro thanks for the additional check and yes this should be safe. Tests are happy, so lets get this in. |
No description provided.