-
Notifications
You must be signed in to change notification settings - Fork 4
perf(input): cut per-character render cost (D2) #41
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,7 +103,6 @@ function UserInputView:render_input(input, status, time) | |
| local apparentHeight = inHeight | ||
|
|
||
| local wrap_forward = vc.wrap_forward | ||
| local wrap_reverse = vc.wrap_reverse | ||
|
|
||
|
|
||
| local vpH = gfx.getHeight() | ||
|
|
@@ -166,7 +165,6 @@ function UserInputView:render_input(input, status, time) | |
| local char = string.usub(s, c, c) | ||
| local color = colors.fg | ||
|
|
||
| local hl_li = wrap_reverse[ln] | ||
| local tlc = vc:translate_from_visible(Cursor(l, c)) | ||
|
|
||
| if tlc then | ||
|
|
@@ -204,11 +202,6 @@ function UserInputView:render_input(input, status, time) | |
| end | ||
| end | ||
| end)() | ||
| local of = calc_overflow(w, text, cursorInfo.cursor) | ||
| --- push any further lines down to display phantom line | ||
| if ofpos and hl_li > cl then | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this functionality being removed without any replacement? I understand it's not the most elegant solution, and would welcome a principled concept on how to do it well, but it has a purpose, don't just drop it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair — I should have put the history in the PR text instead of just calling it dead, that's on me. Here's what I found when I traced it. Before 237e625 ("fix(uiv): proper drawing of wrapped lines + DRY") the adjustment had a reader — it fed the y coordinate directly: |
||
| of = of - 1 | ||
| end | ||
| local dy = (l) * fh | ||
| local dx = (c - 1) * fw | ||
| ViewUtils.write_token(dy, dx, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| local mock = require("tests.mock") | ||
| mock.mock_love({}) | ||
| require("util.view") | ||
|
|
||
| describe('view utils #view', function() | ||
| local prev_gfx | ||
| local color | ||
|
|
||
| setup(function() | ||
| prev_gfx = _G.gfx | ||
| color = { 1, 1, 1, 1 } | ||
| _G.gfx = { | ||
| getColor = function() | ||
| return color[1], color[2], color[3], color[4] | ||
| end, | ||
| setColor = function(r, g, b, a) | ||
| if type(r) == 'table' then | ||
| color = { r[1], r[2], r[3], r[4] } | ||
| else | ||
| color = { r, g, b, a } | ||
| end | ||
| end, | ||
| print = function() end, | ||
| } | ||
| end) | ||
|
|
||
| teardown(function() | ||
| _G.gfx = prev_gfx | ||
| end) | ||
|
|
||
| describe('write_token', function() | ||
| it('leaves the active color untouched', function() | ||
| gfx.setColor(0.1, 0.2, 0.3, 1) | ||
| ViewUtils.write_token(0, 0, 'x', | ||
| { 1, 0, 0, 1 }, { 0, 0, 0, 1 }, false) | ||
| local r, g, b = gfx.getColor() | ||
| assert.same({ 0.1, 0.2, 0.3 }, { r, g, b }) | ||
|
|
||
| ViewUtils.write_token(0, 0, 'x', | ||
| { 1, 0, 0, 1 }, { 0, 0, 0, 1 }, true) | ||
| r, g, b = gfx.getColor() | ||
| assert.same({ 0.1, 0.2, 0.3 }, { r, g, b }) | ||
| end) | ||
| end) | ||
| end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this is actually faster than moving the stack pointer?
And more importantly, that no other state needs to be managed? It's possible, but I'd like to be sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went read the 11.x source to check myself again. From what I see, push('all') is more than a stack pointer move: Graphics::push with STACK_ALL does states.push_back(states.back()) (Graphics.cpp:1622), and DisplayState carries quite a lot — both colors, blend, line settings, scissor, stencil, depth, cull, winding, a StrongRef and StrongRef, and the render target list (a heap vector). pop() then goes through restoreStateChecked (:409), which re-applies fields one by one — some setters run unconditionally (setFont/setShader among them), and the popped copy gets destroyed after. The way I read it, the color-only variant is a subset of that work — restoreStateChecked itself calls setColor when the color differs, so we're keeping that part and dropping the rest. That's mostly why I felt safe calling it cheaper, though I haven't benchmarked it — can do that if you'd like actual numbers. On other state: as far as I can tell, write_token only ever calls setColor and print (print reads the font and transform but doesn't change anything), so color seemed to be the only thing to manage. I did add a small spec pinning "the active color is left untouched" — the thought was, if the function ever needs to touch more state, widening the save back becomes a visible step instead of something to remember. But you know this code's history better — if there's state I'm not seeing, happy to go back to push('all').