Skip to content

Commit 352a39c

Browse files
committed
fix: bench
1 parent c11becc commit 352a39c

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

bench/Bench.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ newtype Velocity = Velocity Int deriving (Show, Generic, NFData)
2020

2121
instance Component Velocity
2222

23-
query :: Query Position
24-
query = Q.fetch & Q.adjust (\(Velocity v) (Position p) -> Position $ p + v)
23+
q :: Query Position
24+
q = fetch & zipFetchMap (\(Velocity v) (Position p) -> Position $ p + v)
2525

26-
run :: Query Position -> World -> [Position]
27-
run q = fst . runIdentity . Q.map q . entities
26+
run :: World -> [Position]
27+
run = fst . runIdentity . Q.query q . entities
2828

2929
main :: IO ()
3030
main = do
3131
let go wAcc = snd $ W.spawn (bundle (Position 0) <> bundle (Velocity 1)) wAcc
3232
!w = foldr (const go) W.empty [0 :: Int .. 10000]
33-
defaultMain [bench "iter" $ nf (run query) w]
33+
defaultMain [bench "iter" $ nf run w]

src/Aztecs/ECS/Query.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ singleMaybe' q es = do
220220
query :: (Monad m) => QueryT m a -> Entities -> m ([a], Entities)
221221
query q es = do
222222
let !(cs', dynQ) = runQuery q $ components es
223-
(as, es') <- mapDyn dynQ es
223+
(as, es') <- queryDyn dynQ es
224224
return (as, es' {components = cs'})
225225

226226
-- | Map a single matched entity.

src/Aztecs/ECS/Query/Dynamic.hs

+10-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module Aztecs.ECS.Query.Dynamic
3939
singleDyn,
4040
singleMaybeDyn,
4141
queryEntitiesDyn,
42-
mapDyn,
42+
readQueryDyn,
4343
mapSingleDyn,
4444
mapSingleMaybeDyn,
4545
readQueryEntitiesDyn,
@@ -144,9 +144,11 @@ zipFetchMapDynM f cId q = snd <$> zipFetchMapAccumDynM (\b a -> ((),) <$> f b a)
144144
zipFetchMapAccumDynM :: (Monad f, Component a) => (b -> a -> f (c, a)) -> ComponentID -> DynamicQueryT f b -> DynamicQueryT f (c, a)
145145
zipFetchMapAccumDynM f cId q = Op $ AdjustM f cId q
146146

147+
{-# INLINE withDyn #-}
147148
withDyn :: ComponentID -> DynamicQueryT f ()
148149
withDyn = Op . With
149150

151+
{-# INLINE withoutDyn #-}
150152
withoutDyn :: ComponentID -> DynamicQueryT f ()
151153
withoutDyn = Op . Without
152154

@@ -383,11 +385,11 @@ readDynQuery (Ap f g) arch = do
383385
pure $ zipWith ($) bs as
384386
readDynQuery (Op op) arch = readOp op arch
385387

386-
-- | Match all entities .
388+
-- | Match all entities.
387389
--
388390
-- @since 0.11
389-
queryDyn :: (Monad m) => DynamicQueryT m a -> Entities -> m [a]
390-
queryDyn q es =
391+
readQueryDyn :: (Monad m) => DynamicQueryT m a -> Entities -> m [a]
392+
readQueryDyn q es =
391393
let qf = queryFilter q
392394
in if Set.null $ filterWith qf
393395
then readDynQuery q $ A.empty {A.entities = Map.keysSet $ entities es}
@@ -427,12 +429,12 @@ singleMaybeDyn q es =
427429
_ -> Nothing
428430
_ -> return Nothing
429431

430-
-- | Map all matched entities.
432+
-- | Match and update all matched entities.
431433
--
432434
-- @since 0.11
433-
{-# INLINE mapDyn #-}
434-
mapDyn :: (Monad m) => DynamicQueryT m a -> Entities -> m ([a], Entities)
435-
mapDyn = mapDyn' id
435+
{-# INLINE queryDyn #-}
436+
queryDyn :: (Monad m) => DynamicQueryT m a -> Entities -> m ([a], Entities)
437+
queryDyn = mapDyn' id
436438

437439
{-# INLINE mapDyn' #-}
438440
mapDyn' ::

0 commit comments

Comments
 (0)