Skip to content

Reusing canvas for rendering - #394

Closed
EpicDima wants to merge 1 commit into
JakeWharton:trunkfrom
EpicDima:epicdima/reduce_number_of_canvases
Closed

Reusing canvas for rendering#394
EpicDima wants to merge 1 commit into
JakeWharton:trunkfrom
EpicDima:epicdima/reduce_number_of_canvases

Conversation

@EpicDima

@EpicDima EpicDima commented Jun 8, 2024

Copy link
Copy Markdown
Contributor

Partial solution for #153.

@EpicDima
EpicDima force-pushed the epicdima/reduce_number_of_canvases branch 5 times, most recently from 538843c to 7965f79 Compare August 20, 2024 13:48
@EpicDima EpicDima mentioned this pull request Aug 26, 2024
Comment on lines +181 to +182
|One
|Two
|One $s
|Two $s

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This seems worse. I don't think we need to optimize statics to reuse the same surface since they're rare, and even when used there's probably only one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I know it looks worse here. I did this consciously, because I made #439 where I delete empty characters at the end of lines, which, in my opinion, eliminates this problem later.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think trimming at the end makes sense for an individual surface, especially the main one. I'll get to that PR soon.

But by combining the static surfaces we're now doing more work to merge them and allocate more space, only to then have to process more to trim the new trailing spaces. And ultimately it results in no change in the output but more code to maintain.

Since in practice there aren't multiple static nodes, and even if there are they're all not rendering at the same time, and even if multiple render they're not rendering much, doing this still doesn't gain us anything.

private var fullWidth: Int = width
private var fullHeight: Int = height

private val rows = ArrayList(fullHeight) { ArrayList(fullWidth) { TextPixel(' ') } }

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't see a big motivation from switching from Array here. Is it because of row resizing? We can accomplish that with a helper https://pl.kotl.in/c_ED2lc0h. I'll file a Kotlin issue to provide such an overload.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I changed it only to change the size out of the box.

@EpicDima
EpicDima force-pushed the epicdima/reduce_number_of_canvases branch from 7965f79 to c801320 Compare September 2, 2024 00:27
@EpicDima EpicDima changed the title Reduce number of canvases for render Reusing canvas for rendering Sep 2, 2024
@EpicDima
EpicDima force-pushed the epicdima/reduce_number_of_canvases branch from c801320 to 629ea04 Compare September 2, 2024 00:29
@JakeWharton

Copy link
Copy Markdown
Owner

Are you okay if I close this? Or do you want to push back more on my claim that this is an uncommon problem?

@EpicDima

Copy link
Copy Markdown
Contributor Author

No problem if you don't think it's necessary 🙂

@EpicDima
EpicDima deleted the epicdima/reduce_number_of_canvases branch January 12, 2025 19:19
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