• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / arche / 12631972980

06 Jan 2025 11:50AM CUT coverage: 100.0%. Remained the same
12631972980

push

github

web-flow
Optimize removal in archetypes (#459)

Zeroing memory of removed components in archetypes to make the GC handle pointers properly takes a significant amount of time. With this change, zeroing is only performed on components for which it is really necessary.

Achieves a speedup of approx. 10-20% for methods that remove entities from or move them between archetypes. Slows down component registration by approx. 40ns per component struct field.

Also introduces separate registry types for components and resources. Speeds up resource type registration by approx. 40ns.

* use a simplified registry for resources
* zero archetype data only when required due to pointers
* extend internal docs
* add benchmark for instantiating a world
* add more registry benchmarks

67 of 67 new or added lines in 5 files covered. (100.0%)

6537 of 6537 relevant lines covered (100.0%)

114573.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/ecs/bitset.go
1
package ecs
2

3
// Data structure for compact storage of booleans.
4
type bitSet struct {
5
        data []uint64
6
}
7

8
// Get a value.
9
func (b *bitSet) Get(bit eid) bool {
3,528,595✔
10
        chunk, bit := bit/wordSize, bit%wordSize
3,528,595✔
11
        mask := uint64(1 << bit)
3,528,595✔
12
        return b.data[chunk]&mask == mask
3,528,595✔
13
}
3,528,595✔
14

15
// Set a value.
16
func (b *bitSet) Set(bit eid, value bool) {
3,836,630✔
17
        chunk, bit := bit/wordSize, bit%wordSize
3,836,630✔
18
        if value {
3,867,131✔
19
                b.data[chunk] |= uint64(1 << bit)
30,501✔
20
        } else {
3,836,630✔
21
                b.data[chunk] &= uint64(^(1 << bit))
3,806,129✔
22
        }
3,806,129✔
23
}
24

25
// Reset all values.
26
func (b *bitSet) Reset() {
33✔
27
        for i := range b.data {
3,900✔
28
                b.data[i] = 0
3,867✔
29
        }
3,867✔
30
}
31

32
// Extend to hold at least the given bits.
33
func (b *bitSet) ExtendTo(length int) {
38,303✔
34
        chunks, bit := length/wordSize, length%wordSize
38,303✔
35
        if bit > 0 {
48,859✔
36
                chunks++
10,556✔
37
        }
10,556✔
38
        if len(b.data) >= chunks {
76,180✔
39
                return
37,877✔
40
        }
37,877✔
41

42
        old := b.data
426✔
43
        b.data = make([]uint64, chunks)
426✔
44

426✔
45
        copy(b.data, old)
426✔
46
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc