Skip to content

Commit cfa1101

Browse files
authored
Undo slice pooling for filters/queries (#423)
* undo slice pooling for filters/queries * undo entity column and table ID in query
1 parent 720bc61 commit cfa1101

25 files changed

+501
-721
lines changed

ecs/column.go

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@ import (
77

88
// column storage for components in an table.
99
type column struct {
10-
columnLayout
11-
data reflect.Value // data buffer
12-
elemType reflect.Type // element type of the column
13-
index uint32 // index of the column in the containing table
14-
isRelation bool // whether this column is for a relation component
15-
isTrivial bool // Whether the column's type is trivial , i.e. without pointers.
16-
}
17-
18-
// columnLayout contains the minimal necessary information for column.Get.
19-
type columnLayout struct {
20-
pointer unsafe.Pointer // pointer to the first element
21-
itemSize uintptr // memory size of items
22-
target Entity // target entity if for a relation component
10+
data reflect.Value // data buffer
11+
pointer unsafe.Pointer // pointer to the first element
12+
itemSize uintptr // memory size of items
13+
elemType reflect.Type // element type of the column
14+
target Entity // target entity if for a relation component
15+
index uint32 // index of the column in the containing table
16+
isRelation bool // whether this column is for a relation component
17+
isTrivial bool // Whether the column's type is trivial , i.e. without pointers.
2318
}
2419

2520
// newColumn creates a new column for a given type and capacity.
@@ -29,11 +24,9 @@ func newColumn(index uint32, tp reflect.Type, itemSize uintptr, isRelation bool,
2924
pointer := data.Addr().UnsafePointer()
3025

3126
return column{
32-
columnLayout: columnLayout{
33-
pointer: pointer,
34-
itemSize: itemSize,
35-
target: target,
36-
},
27+
pointer: pointer,
28+
itemSize: itemSize,
29+
target: target,
3730
index: index,
3831
data: data,
3932
isRelation: isRelation,
@@ -43,7 +36,7 @@ func newColumn(index uint32, tp reflect.Type, itemSize uintptr, isRelation bool,
4336
}
4437

4538
// Get returns a pointer to the component at the given index.
46-
func (c *columnLayout) Get(index uintptr) unsafe.Pointer {
39+
func (c *column) Get(index uintptr) unsafe.Pointer {
4740
return unsafe.Add(c.pointer, index*c.itemSize)
4841
}
4942

@@ -137,11 +130,6 @@ func (c *entityColumn) Get(index uintptr) unsafe.Pointer {
137130
return unsafe.Add(c.pointer, index*entitySize)
138131
}
139132

140-
// GetEntity returns the entity at the given index.
141-
func (c *entityColumn) GetEntity(index uintptr) Entity {
142-
return *(*Entity)(unsafe.Add(c.pointer, index*entitySize))
143-
}
144-
145133
// CopyToEnd copies from the given column to the end of this column.
146134
// Column length must be increased before.
147135
func (c *entityColumn) CopyToEnd(from *entityColumn, ownLen uint32, count uint32) {

ecs/exchange_gen.go

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs/filter.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,12 @@ func (f UnsafeFilter) Exclusive() UnsafeFilter {
3838

3939
// Query returns a new query matching this filter and the given entity relation targets.
4040
func (f UnsafeFilter) Query(relations ...Relation) UnsafeQuery {
41-
f.world.storage.mu.Lock()
42-
lock := f.world.lock()
43-
rel := f.world.storage.slices.relationsPool.Get()
44-
f.world.storage.mu.Unlock()
45-
46-
rel = relationSlice(relations).ToRelationIDsForUnsafe(f.world, rel)
41+
rel := relationSlice(relations).ToRelationIDsForUnsafe(f.world, nil)
4742
return UnsafeQuery{
4843
world: f.world,
4944
filter: f.filter,
5045
relations: rel,
51-
lock: lock,
46+
lock: f.world.lockSafe(),
5247
cursor: cursor{
5348
archetype: -1,
5449
table: -1,

0 commit comments

Comments
 (0)