我有一个 Haskell 程序,它处理一个文本文件并构建一个Map
(包含数百万个元素)。整个过程可以运行2-3分钟。我发现调整 -H 和 -A 选项会对运行时间产生很大影响。
有关于 RTS 的此功能的文档,但对我来说很难阅读,因为我不知道 GC 理论中的算法和术语。我正在寻找一个技术含量较低的解释,最好是针对 Haskell/GHC。有没有关于为这些选项选择合理值的参考资料?
编辑:这就是代码,它为给定的单词列表构建了一个 trie。
buildTrie :: [B.ByteString] -> MyDFA
buildTrie l = fst3 $ foldl' step (emptyDFA, B.empty, 1) $ sort $ map B.reverse l where
step :: (MyDFA , B.ByteString, Int) -> B.ByteString -> (MyDFA , B.ByteString, Int)
step (dfa, lastWord, newIndex) newWord = (insertNewStates, newWord, newIndex + B.length newSuffix) where
(pref, lastSuffix, newSuffix) = splitPrefix lastWord newWord
branchPoint = transStar dfa pref
--new state labels for the newSuffix path
newStates = [newIndex .. newIndex + B.length newSuffix - 1]
--insert newStates
insertNewStates = (foldl' (flip insertTransition) dfa $ zip3 (branchPoint:init newStates) (B.unpack newSuffix) newStates)