anchor.diff:          subscriptionId
           event
           (callback : EcsCallback<'d, 's>) =
  -        match subscriptions.TryGetValue event with
  -        | (true, callbacks) ->
  -            callbacks.Add (subscriptionId, this.BoxCallback<'d, 's> callback)
  -            subscriptionId
  -        | (false, _) ->
  -            let callbacks = dictPlus HashIdentity.Structural [(subscriptionId, this.BoxCallback<'d, 's> callback)]
  -            subscriptions.Add (event, callbacks)
  -            subscriptionId
  +        let subscriptionId =
  +            match subscriptions.TryGetValue event with
  +            | (true, callbacks) ->
  +                callbacks.Add (subscriptionId, this.BoxCallback<'d, 's> callback)
  +                subscriptionId
  +            | (false, _) ->
  +                let callbacks = dictPlus HashIdentity.Structural [(subscriptionId, this.BoxCallback<'d, 's> callback)]
  +                subscriptions.Add (event, callbacks)
  +                subscriptionId
  +        match event.EventType with
  +        | ComponentEvent (entityRef, _) ->
  +            match subscribedEntities.TryGetValue entityRef with
  +            | (true, count) -> subscribedEntities.[entityRef] <- inc count
  +            | (false, _) -> subscribedEntities.Add (entityRef, 1)
  +        | _ -> ()
  +        subscriptionId
   
       member this.Subscribe<'d, 's> event callback =
           this.SubscribePlus<'d, 's> this.SubscriptionId event callback |> ignore
   
       member this.Unsubscribe event subscriptionId =
  -        match subscriptions.TryGetValue event with
  -        | (true, callbacks) -> callbacks.Remove subscriptionId
  -        | (false, _) -> false
  +        let result =
  +            match subscriptions.TryGetValue event with
  +            | (true, callbacks) -> callbacks.Remove subscriptionId
  +            | (false, _) -> false
  +        if result then
  +            match event.EventType with
  +            | ComponentEvent (entityRef, _) ->
  +                match subscribedEntities.TryGetValue entityRef with
  +                | (true, count) ->
  +                    if count = 1
  +                    then subscribedEntities.Remove entityRef |> ignore<bool>
  +                    else subscribedEntities.[entityRef] <- inc count
  +                | (false, _) -> failwith "Subscribed entities count mismatch."
  +            | _ -> failwith "Subscribed entities count mismatch."
  +        result
   
       member this.RegisterComponentType<'c when 'c : struct and 'c :> 'c Component> componentName =
           match componentTypes.TryGetValue componentName with
           | (true, _) -> failwith "Component type already registered."
           | (false, _) -> componentTypes.Add (componentName, typeof<'c>)
   
  -    member this.RegisterTerm (termName : string) term (entityRef : EntityRef) (state : 's) =
  +    member this.RegisterTerm (termName : string) term (entityRef : EntityRef) =
           if termName.StartsWith Constants.Ecs.IntraComponentPrefix then failwith "Term names that start with '@' are for internal use only."
           if (match term with Intra _ -> true | _ -> false) then failwith "Intra components are for internal use only."
           match archetypeSlots.TryGetValue entityRef.EntityId with
  
positive.code:     static member PostUpdate = { EventName = "PostUpdate"; EventType = GlobalEvent }
      static member PostUpdateParallel = { EventName = "PostUpdateParallel"; EventType = GlobalEvent }
      static member Actualize = { EventName = "Actualize"; EventType = GlobalEvent }
      static member Register compName = { EventName = "Register"; EventType = ComponentEvent compName }
      static member Unregistering compName = { EventName = "Unregistering"; EventType = ComponentEvent compName }
      static member Change entityRef = { EventName = "Change"; EventType = EntityEvent entityRef }
  
  and [<StructuralEquality; NoComparison>] Term =
  
negative.code:             let archetype = archetypeSlot.Archetype
              let comps = archetype.GetComponents archetypeSlot.ArchetypeIndex
              let eventData = { EntityRef = entityRef; ContextName = compName }
              let state = this.Publish<EcsRegistrationData, obj> (EcsEvents.Unregistering entityRef compName) eventData (state :> obj) :?> 's
              archetype.Unregister archetypeSlot.ArchetypeIndex
              archetypeSlots.Remove entityRef.EntityId |> ignore<bool>
              comps.Remove compName |> ignore<bool>
  