On Wed, Dec 1, 2010 at 14:47, Iustin Pop <[email protected]> wrote:
> When loading big clusters, the association lists become a bit slow, so > we'll replace this with a simple Map String Int; the change is trivial > and can be reverted easily, while it brings up a good speedup in the > data loading. > --- > Ganeti/HTools/Loader.hs | 13 ++++++++----- > Ganeti/HTools/Types.hs | 4 +++- > 2 files changed, 11 insertions(+), 6 deletions(-) > > diff --git a/Ganeti/HTools/Loader.hs b/Ganeti/HTools/Loader.hs > index 30a2614..e1f35a0 100644 > --- a/Ganeti/HTools/Loader.hs > +++ b/Ganeti/HTools/Loader.hs > @@ -40,6 +40,7 @@ module Ganeti.HTools.Loader > import Data.Function (on) > import Data.List > import Data.Maybe (fromJust) > +import qualified Data.Map as M > import Text.Printf (printf) > > import qualified Ganeti.HTools.Container as Container > @@ -78,14 +79,14 @@ data Request = Request RqType Node.List Instance.List > [String] > -- | Lookups a node into an assoc list. > lookupNode :: (Monad m) => NameAssoc -> String -> String -> m Ndx > lookupNode ktn inst node = > - case lookup node ktn of > + case M.lookup node ktn of > Nothing -> fail $ "Unknown node '" ++ node ++ "' for instance " ++ > inst > Just idx -> return idx > > -- | Lookups an instance into an assoc list. > lookupInstance :: (Monad m) => NameAssoc -> String -> m Idx > lookupInstance kti inst = > - case lookup inst kti of > + case M.lookup inst kti of > Nothing -> fail $ "Unknown instance '" ++ inst ++ "'" > Just idx -> return idx > > @@ -93,9 +94,11 @@ lookupInstance kti inst = > assignIndices :: (Element a) => > [(String, a)] > -> (NameAssoc, [(Int, a)]) > -assignIndices = > - unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, setIdx v idx))) > - . zip [0..] > +assignIndices nodes = > + let (na, idx_node) = > + unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, setIdx v idx))) > + . zip [0..] $ nodes > + in (M.fromList na, idx_node) > > -- | Assoc element comparator > assocEqual :: (Eq a) => (a, b) -> (a, b) -> Bool > diff --git a/Ganeti/HTools/Types.hs b/Ganeti/HTools/Types.hs > index 200163b..7a0c6db 100644 > --- a/Ganeti/HTools/Types.hs > +++ b/Ganeti/HTools/Types.hs > @@ -55,6 +55,8 @@ module Ganeti.HTools.Types > , queryTimeout > ) where > > +import qualified Data.Map as M > + > -- | The instance index type. > type Idx = Int > > @@ -62,7 +64,7 @@ type Idx = Int > type Ndx = Int > > -- | The type used to hold name-to-idx mappings. > -type NameAssoc = [(String, Int)] > +type NameAssoc = M.Map String Int > > -- | A separate name for the cluster score type. > type Score = Double > -- > 1.7.2.3 > > LGTM
