Skip to content

Commit

Permalink
Add change detection benchmark including visibility optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-pate committed Jan 27, 2025
1 parent e0a2ed1 commit 7b770a9
Show file tree
Hide file tree
Showing 15 changed files with 534 additions and 58 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,42 @@ name: Continuous integration

jobs:
gdlint:
name: gdlint scripts
name: Lint and Format checks
runs-on: ubuntu-latest

steps:
# Check out the repository
- name: Checkout
uses: actions/checkout@v4

# Ensure python is installed
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

# Install gdtoolkit
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install 'gdtoolkit==4.3.2'
# Lint the godot-xr-tools addon
- name: Lint and Format Checks
run: |
./check.sh
benchmark:
name: Performance Benchmark
runs-on: ubuntu-latest
container:
image: barichello/godot-ci:latest

steps:
- name: Checkout
uses: actions/checkout@v4

# TODO: run with the previous version and compare the results!
- name: Benchmark
run: |
./test.sh --benchmark-only
test:
name: Test
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/.godot
addons/*
/addons/*
!addons/DataBindControls
/benchmark.json

.py_venv
.DS_STORE
2 changes: 1 addition & 1 deletion addons/DataBindControls/bind_items.gd
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func _get_items_target():
return parent.get_popup() if parent.has_method("get_popup") else parent


func _get_array_value(silent := false):
func _get_array_value():
var target = _bound_array.get_target()
return _bound_array.get_value(target) if target else []

Expand Down
30 changes: 25 additions & 5 deletions addons/DataBindControls/bind_repeat.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ var _detected_change_log := []
var _bound_array: BindTarget


func _init():
add_to_group(Util.BIND_GROUP)


func _ready():
if Engine.is_editor_hint():
return
Expand Down Expand Up @@ -108,15 +104,18 @@ func detect_changes(new_value: Array = []) -> bool:
return change_detected


func _assign_item(child, item, i):
func _assign_item(child, item, i) -> bool:
var result := false
if array_bind && target_property in child:
var m = child[target_property]
var current_value = child[target_property]
if typeof(current_value) != typeof(item) || current_value != item:
result = true
_detected_change_log.append(
"[%s].%s: %s != %s" % [i, target_property, current_value, item]
)
child[target_property] = item
return result


func _notification(what):
Expand All @@ -126,13 +125,34 @@ func _notification(what):
_template = null


func _parent_visibility_changed():
DataBindings.update_bind_visibility(self)


func _enter_tree():
if Engine.is_editor_hint():
return
if !owner && _owner:
owner = _owner
_owner = null
assert(owner)
DataBindings.add_bind(self)
var p := get_parent()
if p && p.has_signal("visibility_changed"):
p.visibility_changed.connect(_parent_visibility_changed)


func _exit_tree():
if Engine.is_editor_hint():
return
DataBindings.remove_bind(self)
var p := get_parent()
if p && p.has_signal("visibility_changed"):
p.visibility_changed.disconnect(_parent_visibility_changed)


func change_count():
return len(_detected_change_log)


func get_desc():
Expand Down
46 changes: 21 additions & 25 deletions addons/DataBindControls/binds.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ var _binds := {}
var _detected_change_log := []


func _init():
add_to_group(Util.BIND_GROUP)


func _get_property_list():
# it seems impossible to do an inherited call of _get_property_list() directly.
return _binds_get_property_list()
Expand Down Expand Up @@ -138,12 +134,14 @@ func _enter_tree():
if Engine.is_editor_hint():
return
_bind_targets()
DataBindings.add_bind(self)


func _bind_targets():
var parent := get_parent()
for p in _binds:
_bind_target(p, parent)
# visibility changed notifications don't propagate to non-controls
if parent.has_signal("visibility_changed"):
parent.visibility_changed.connect(_on_parent_visibility_changed)

Expand Down Expand Up @@ -172,6 +170,7 @@ func _bind_target(p: String, parent: Node) -> void:
func _exit_tree():
if Engine.is_editor_hint():
return
DataBindings.remove_bind(self)
_unbind_targets()


Expand All @@ -185,6 +184,10 @@ func _unbind_targets():
parent.visibility_changed.disconnect(_on_parent_visibility_changed)


func _on_parent_visibility_changed():
DataBindings.update_bind_visibility(self)


func _unbind_target(p: String, parent: Node):
if p in PASSTHROUGH_PROPS:
return
Expand All @@ -198,20 +201,12 @@ func _unbind_target(p: String, parent: Node):
parent.disconnect(SIGNAL_PROPS[p], Callable(self, method))


func _on_parent_visibility_changed():
# If visibility changes we need to redetect changes because
# changes are ignored when controls are hidden.
DataBindings.detect_changes()


func _on_parent_prop_changed0(prop_name: String):
_on_parent_prop_changed1(null, prop_name)


func _on_parent_prop_changed1(value, prop_name: String):
var parent := get_parent()
if prop_name != "visible" && !parent.is_visible_in_tree():
return
value = parent[prop_name]
var bt = _bound_targets[_binds[prop_name]]
var target = bt.get_target()
Expand All @@ -233,19 +228,16 @@ func detect_changes() -> bool:
var target = bt.get_target()
if target:
var parent = get_parent()
if parent.is_visible_in_tree() || p == "visible":
var value = bt.get_value(target)
if !_equal_approx(parent[p], value):
_detected_change_log.append(
"%s: %s != %s" % [bt.full_path, parent[p], value]
)
changes_detected = true
var cp
if "caret_column" in parent:
cp = parent.caret_column
parent[p] = value
if "caret_column" in parent:
parent.caret_column = cp
var value = bt.get_value(target)
if !_equal_approx(parent[p], value):
_detected_change_log.append("%s: %s != %s" % [bt.full_path, parent[p], value])
changes_detected = true
var cp
if "caret_column" in parent:
cp = parent.caret_column
parent[p] = value
if "caret_column" in parent:
parent.caret_column = cp
return changes_detected


Expand All @@ -263,5 +255,9 @@ func _equal_approx(a, b):
return a == b


func change_count():
return len(_detected_change_log)


func get_desc():
return "%s\n%s" % [get_path(), "\n".join(_detected_change_log)]
Loading

0 comments on commit 7b770a9

Please sign in to comment.