Does it make sense to use QCryptographicHash to generate shorter keys from local URL?
-
Hi.
I have modifiedQQuickFolderListModelto also provide previews of embedded media art.It uses
QPixmapCacheandQNetworkDiskCachefor which I currently use the full local URL path as key, but that doesn't seem very efficient, as those strings can get relatively long.Does it make sense to use
QCryptographicHashto create a 128bit MD5 hash from the path instead in order to speed up key lookup ofQPixmapCacheandQNetworkDiskCache?
Will those benefits (if any) offset the hash computation overhead? -
Hi.
I have modifiedQQuickFolderListModelto also provide previews of embedded media art.It uses
QPixmapCacheandQNetworkDiskCachefor which I currently use the full local URL path as key, but that doesn't seem very efficient, as those strings can get relatively long.Does it make sense to use
QCryptographicHashto create a 128bit MD5 hash from the path instead in order to speed up key lookup ofQPixmapCacheandQNetworkDiskCache?
Will those benefits (if any) offset the hash computation overhead?@Diracsbracket said in Does it make sense to use QCryptographicHash to generate shorter keys from local URL?:
Will those benefits (if any) offset the hash computation overhead?
I don't think you will gain anything. But you always can try both and compare.
-
@Diracsbracket said in Does it make sense to use QCryptographicHash to generate shorter keys from local URL?:
Will those benefits (if any) offset the hash computation overhead?
I don't think you will gain anything. But you always can try both and compare.
@jsulm
Thanks for reacting!From this post:
https://stackoverflow.com/questions/22607076/does-stdmapfind-performance-depend-on-the-key-size/22607412
I got a simple optimization hint to speed up key string comparison operations:
Instead of using the full path as is, which in the case of a local file system consists of many identical prefixes, I can simply (partially) permute the path string, e.g, if the path isprefix + filename, use instead:key = filename + prefixOr something in that vein.
-
@jsulm
Thanks for reacting!From this post:
https://stackoverflow.com/questions/22607076/does-stdmapfind-performance-depend-on-the-key-size/22607412
I got a simple optimization hint to speed up key string comparison operations:
Instead of using the full path as is, which in the case of a local file system consists of many identical prefixes, I can simply (partially) permute the path string, e.g, if the path isprefix + filename, use instead:key = filename + prefixOr something in that vein.
@Diracsbracket I'm wondering whether you're over-engineering (or doing premature optimisations)?
Do you actually experience performance issues? -
@Diracsbracket I'm wondering whether you're over-engineering (or doing premature optimisations)?
Do you actually experience performance issues?@jsulm said in Does it make sense to use QCryptographicHash to generate shorter keys from local URL?:
I'm wondering whether you're over-engineering (or doing premature optimisations)?
You're right, certainly since I'm doing this on a Pi4 with probably a lot more room for optimization. But if anything can be done even a bit more efficiently, then why not. Every little little bit helps.
Do you actually experience performance issues?
Well, those performance issues are probably more related to the current disk I/O performance on the Pi, and the fact that my disk cache is still on the micro SD instead of on an external SSD drive...
Thanks!
-
@jsulm said in Does it make sense to use QCryptographicHash to generate shorter keys from local URL?:
I'm wondering whether you're over-engineering (or doing premature optimisations)?
You're right, certainly since I'm doing this on a Pi4 with probably a lot more room for optimization. But if anything can be done even a bit more efficiently, then why not. Every little little bit helps.
Do you actually experience performance issues?
Well, those performance issues are probably more related to the current disk I/O performance on the Pi, and the fact that my disk cache is still on the micro SD instead of on an external SSD drive...
Thanks!
Permuting parts of the path string does not work, unfortunately, since QNetworkDiskCache requires valid URLs...