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

Improve performance of ren_draw_rect #935

Merged
merged 1 commit into from
Apr 20, 2022

Conversation

Guldoman
Copy link
Member

We color a 1x1 SDL_Surface with the desired color. This surface is then stretched over the area we need to cover using SDL_BlitScaled.

This way we avoid having to do the blending ourselves.

We color a 1x1 `SDL_Surface` with the desired color. This surface is 
then stretched over the area we need to cover using `SDL_BlitScaled`.
This way we avoid having to do the blending ourselves.
@jgmdev
Copy link
Member

jgmdev commented Apr 19, 2022

Tested this change and everything is working normally, would be nice to have some figures on the performance gains.

@adamharrison
Copy link
Member

Sounds to be good; would be good to have some numbers here for historical traceability purposes, but see no reason why we can't merge now.

@adamharrison adamharrison merged commit 1439b59 into lite-xl:master Apr 20, 2022
@Guldoman
Copy link
Member Author

Guldoman commented Apr 20, 2022

Ok, so using this as a benchmark:

local tt
local tot = 0
local n = 0

local ef = renderer.end_frame
function renderer.end_frame()
  local t = system.get_time()
  if not tt then tt = t end
  ef()
  local e = system.get_time()
  tot = tot + e - t
  n = (n + 1) % 100
  if n == 0 then
    print(string.format("%.4f\t%.4f", tot/100, e - tt))
    tt = e
    tot = 0
  end
end

local clr = { 0, 0, 0, 20 }

local rvd = core.root_view.draw
function core.root_view:draw()
  rvd(self)
  renderer.draw_rect(0, 0, core.root_view.size.x, core.root_view.size.y, clr)
  clr[1] = (clr[1] + 1) % 255
  core.redraw = true
end

which basically draws a transparent rectangle over the whole screen and measures how much it takes to draw 100 frames.

Note: by drawing the rectangle changing color each frame, we force the redraw of the whole window. This means that the time includes also drawing the interface.
This shouldn't affect the benchmark times because the interface doesn't use transparent rectangles but only completely opaque ones, which aren't really touched by this PR.
So the time it takes to draw the interface is the same time in both cases, and the difference is due to the drawing of the transparent rectangle.

The results are:
Before:

Average (s) 100 frames (s)
0.0242 2.4900
0.0248 2.5487
0.0264 2.7106
0.0235 2.4078
0.0245 2.5085
0.0256 2.6342
0.0246 2.5337
0.0244 2.5031
0.0242 2.4848
0.0241 2.4782

After:

Average (s) 100 frames (s)
0.0163 1.7272
0.0158 1.6764
0.0156 1.6755
0.0157 1.6638
0.0158 1.6788
0.0157 1.6693
0.0154 1.6592
0.0160 1.7253
0.0158 1.6965
0.0158 1.6818

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants