Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Improve speed #11

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
# Be aware the health of this package is based on these
# analyse options, we will get the most health points if
# we do not change anything, see:
# https://pub.dev/help#health

# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
linter:
rules:
- unnecessary_brace_in_string_interps
- non_constant_identifier_names
- cancel_subscriptions
include: package:flame_lint/analysis_options.yaml

analyzer:
exclude:
Expand Down
70 changes: 70 additions & 0 deletions benchmark/component_benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Dont use forEcah method! See details:
// https://itnext.io/comparing-darts-loops-which-is-the-fastest-731a03ad42a2
// ignore_for_file: prefer_foreach

import 'package:benchmark/benchmark.dart';
import 'package:oxygen/oxygen.dart';

void main() {
group('Component', () {
group('With 100k entities', () {
World? world;

Filter? filter100;
Filter? filter50;

ComponentPool<Test100Component>? pool100;
ComponentPool<Test50Component>? pool50;

setUp(() {
world = World();
pool100 = world!.getPool(Test100Component.new);
pool50 = world!.getPool(Test50Component.new);

for (var i = 0; i < 100000; i++) {
final entity = world!.createEntity();

pool100!.add(entity);
if (i.isEven) {
pool50!.add(entity);
}
}

filter100 = world!.filter(Test100Component.new).end();
filter50 = world!.filter(Test50Component.new).end();
});

tearDown(() {
world = null;
});

group('100%', () {
benchmark('Iterate over 100% of the entities without getting', () {
for (final _ in filter100!) {}
});

benchmark('Iterate over 100% of the entities with getting', () {
for (final entity in filter100!) {
pool100!.get(entity);
}
});
});

group('50%', () {
benchmark('Iterate over 50% of the entities without getting', () {
for (final _ in filter50!) {}
});

benchmark('Iterate over 50% of the entities with getting', () {
for (final entity in filter50!) {
pool50!.get(entity);
}
});
});
});
});
}

class Test100Component extends Component {}

class Test50Component extends Component {}
53 changes: 53 additions & 0 deletions benchmark/component_pool_benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:benchmark/benchmark.dart';
import 'package:oxygen/oxygen.dart';

class TestObject extends Component {
int? value;

@override
void init([int? data]) {
value = data ?? 0;
}

@override
void reset() {
value = null;
}
}

void main() {
group('ObjectPool', () {
group('creating ComponentPool', () {
late World world;

setUp(() {
world = World();
});

benchmark('with 100k instances', () {
ComponentPool<TestObject>(world, TestObject.new, 0, 100000, 100000);
});
});

group('registered ComponentPool', () {
late World world;
final entities = <Entity>[];
late ComponentPool<TestObject> pool;

setUp(() {
world = World();
pool = world.getPool(TestObject.new);
for (var i = 0; i <= 100000; i++) {
entities.add(world.createEntity());
}
});

benchmark('add 100k entities', () {
final length = entities.length;
for (var i = 0; i < length; i++) {
pool.add(entities[i]);
}
});
});
});
}
40 changes: 40 additions & 0 deletions benchmark/filter_benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:benchmark/benchmark.dart';
import 'package:oxygen/oxygen.dart';

class Test100Component extends Component {}

class Test50Component extends Component {}

void main() {
group('Filter', () {
group('With 100k entities', () {
World? world;

setUp(() {
world = World();
final pool100 = world!.getPool(Test100Component.new);
final pool50 = world!.getPool(Test50Component.new);
for (var i = 0; i < 100000; i++) {
final entity = world!.createEntity();

pool100.add(entity);
if (i.isEven) {
pool50.add(entity);
}
}
});

tearDown(() {
world = null;
});

benchmark('creating a Filter that matches 100% of all the entities', () {
world!.filter(Test100Component.new).end();
});

benchmark('creating a Filter that matches 50% of all the entities', () {
world!.filter(Test50Component.new).end();
});
});
});
}
38 changes: 0 additions & 38 deletions benchmark/object_pool_benchmark.dart

This file was deleted.

56 changes: 0 additions & 56 deletions benchmark/query_benchmark.dart

This file was deleted.

Loading