-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
insertGlobal
calls calculateHash
and invokes lookup
, which calculateHash
again. Hashing could be relatively expensive for large inputs, it would be great to avoid doing it twice.
haskell-symbolize/src/Symbolize/SymbolTable.hs
Lines 80 to 94 in fa328e8
insertGlobal ba# = do | |
GlobalSymbolTable gsymtab sipkey <- globalSymbolTable | |
let !key = calculateHash sipkey ba# | |
-- SAFETY: If the table IORef contested, | |
-- this might trigger `weak` creation for the same bytestring from multiple threads | |
-- at the same time. | |
-- But finalization is idempotent, and only when a thread finally wins the Compare-and-Swap | |
-- will its `weak` pointer be inserted (or alternatively another previously-inserted `ba` returned). | |
-- So once this function returns, we can be sure we've returned a deduplicated ByteArray | |
!weak <- mkWeakSymbol ba# (removeGlobal key) | |
IORef.atomicModifyIORef' gsymtab $ \table -> | |
case lookup ba# sipkey table of | |
Just ba -> (table, ba) | |
Nothing -> | |
(insert key weak table, ByteArray ba#) |
haskell-symbolize/src/Symbolize/SymbolTable.hs
Lines 118 to 121 in fa328e8
lookup ba# sipkey (SymbolTable table) = do | |
let !key = calculateHash sipkey ba# | |
weaks <- IntMap.lookup (hashToInt key) table | |
Foldable.find (\other -> other == ByteArray ba#) (aliveWeaks weaks) |
Qqwy
Metadata
Metadata
Assignees
Labels
No labels