Skip to content

boost speed of bucket in the pressence of selection by about 87% - #1304

Merged
OverloadedOrama merged 6 commits into
Orama-Interactive:masterfrom
Variable-ind:optimize-bucket
Jul 19, 2025
Merged

OverloadedOrama merged 6 commits into
Orama-Interactive:masterfrom
Variable-ind:optimize-bucket

Conversation

@Variable-ind

@Variable-ind Variable-ind commented Jul 15, 2025 •

Copy link
Copy Markdown
Contributor

This introduces two independent optimizations:

1. lock_selection_rect optimization:

Stores existing selection rect as cache and forces get_selection_rect in SelectionMap to use cache instead. use this to save time when the rect isn't meant to change between repeated calls (e.g see it's use in Bucket tool _flood_fill). This causes roughly an 87% boost to the area fill algorithm

2. area_fill compatible with selection size:

when segments were created in _compute_segments_for_image

for j in image.get_height():
	_add_new_segment(j)

When we have selection, this ends up adding segments not necessary for calculation. As an optimization, i change it to

var y_range = [0, image.get_height()]
	_area_end_idx = project.size.y - 1
	_area_start_idx = 0
	if project.has_selection:
		var selection_rect := project.selection_map.get_selection_rect(project)
		_area_start_idx = selection_rect.position.y
		_area_end_idx = selection_rect.end.y - 1
		y_range = [selection_rect.position.y, selection_rect.end.y]
	for j in range(y_range[0], y_range[1]):
		_add_new_segment(j)

This dramatically decreases the fill time even further.

Benchmark of area_fill on a 30x30 selection in a 646x646 canvas

Version Area fill time (msec)
master 3834
PR 32

Related optimization that tagged along.

  • The lock_selection_rect optimization is used by draw_tool and draw_fill_gap as well (this will be noticeable when drawing a line using Pencil on a 5000x5000 canvas in presence of selection).

@Variable-ind Variable-ind mentioned this pull request Jul 15, 2025
@Variable-ind
Variable-ind marked this pull request as draft July 15, 2025 16:01
@Variable-ind
Variable-ind marked this pull request as ready for review July 15, 2025 17:03

@OverloadedOrama OverloadedOrama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you!

@OverloadedOrama
OverloadedOrama merged commit 2356940 into Orama-Interactive:master Jul 19, 2025
@Variable-ind
Variable-ind deleted the optimize-bucket branch July 19, 2025 05:58
@Variable-ind Variable-ind mentioned this pull request Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants