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

Migrate to Lua 5.4 #781

Merged
merged 1 commit into from
Jan 8, 2022
Merged

Migrate to Lua 5.4 #781

merged 1 commit into from
Jan 8, 2022

Conversation

Jan200101
Copy link
Contributor

  • floor every calculation that results in floating point numbers
  • replace bit32 usage with pure lua replacement
  • replace math.pow with ^2
  • update meson.build to check for lua5.4 and lua (Lua does not have an official pkgconf and the names distros differs between distros, luaMAJOR.MINOR and lua being the most common ones)
  • remove references to lua functions that are no longer available
  • replace lua.wrap pointing to franko/lua to the lua.wrap maintained by WrapDB

@adamharrison
Copy link
Member

adamharrison commented Dec 29, 2021

Based on the discussion #556 , and on discord, I think this is the way to go. If there's no strenuous objections here (@franko, your input would be appreciated, if you have some time to comment); but tl;dr from #556, 5.4 is just way more supported, more performant, and all-in-all a better way to go moving forward.

And those who really desperately want jit, can just swap out the bit.lua module.

I also like the fact that we're no longer vendoring lua; that should make it generally easier to upgrade and switch versions without having to maintain the repository ourselves.

@@ -72,7 +73,7 @@ local function retrieve_syntax_state(incoming_syntax, state)
-- syntax we're using. Rather than walking the bytes, and calling into
-- `syntax` each time, we could probably cache this in a single table.
for i = 0, 2 do
local target = bit32.extract(state, i*8, 8)
local target = bit.extract(state, i*8, 8)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The calls to bit32.extract and bit32.replace should probably be replaced with more native logic.

I'm not fluent with Lua so its probably best I leave this to someone else.

@@ -114,7 +115,7 @@ function tokenizer.tokenize(incoming_syntax, text, state)
-- Should be used to set the state variable. Don't modify it directly.
local function set_subsyntax_pattern_idx(pattern_idx)
current_pattern_idx = pattern_idx
state = bit32.replace(state, pattern_idx, current_level*8, 8)
state = bit.replace(state, pattern_idx, current_level*8, 8)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

see previous

Comment on lines +14 to +28
function bit.extract(n, field, width)
local r = trim(field)
local f = width
r = (r >> f) & mask(width)
return r
end

function bit.replace(n, v, field, width)
local r = trim(v);
local v = trim(field);
local f = width
local m = mask(width);
r = (r & ~(m << f)) | ((v & m) << f);
return r
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These functions have been crafted by looking at the lua-bit32 implementation of them and rewriting them in Lua

@@ -42,7 +42,7 @@ end


function common.distance(x1, y1, x2, y2)
return math.sqrt(math.pow(x2-x1, 2)+math.pow(y2-y1, 2))
return math.sqrt(((x2-x1) ^ 2)+((y2-y1) ^ 2))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

math.pow has been deprecated with Lua 5.3
https://www.lua.org/manual/5.3/manual.html#8.2

data/core/statusview.lua Outdated Show resolved Hide resolved
lua_dep = dependency('lua5.4', required : false)
if not lua_dep.found()
lua_dep = dependency('lua', fallback: ['lua', 'lua_dep'],
default_options: ['line_editing=false', 'default_library=static']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

line_editing is equivalent to use_readline
default_library=static is equivalent to shared=false

@Jan200101
Copy link
Contributor Author

For future reference

the .wrap was gathered from https://mesonbuild.com/Wrapdb-projects.html which includes the correct patch links that includes the meson files

@adamharrison
Copy link
Member

If there's no comment from Franko on this, I will merge as of Friday (the 7th).

@franko
Copy link
Member

franko commented Jan 5, 2022

In this moment I don't have enough time to follow the developments that are going on in the master branch but I am glad to see the project moving forward.

As for the transition to Lua 5.4 I have no objections, you can proceed to merge. I think the LuaJIT branch will just remain an experimental build I did for the 2.0 branch, that's all.

@adamharrison adamharrison merged commit 93076bd into lite-xl:master Jan 8, 2022
@adamharrison
Copy link
Member

OK; actually, after merging these changes, I'm experiencing a major performance regression (most noticeable while scrolling). Does anyone else see this? I may actually want to revert this if that's the case, until we can identify the underlying cause.

@adamharrison
Copy link
Member

OK. So I'm pretty sure this actually isn't CPU judder; I checked the CPU usage; and it's actually down in 5.4 from what it was before (this is expected); but it still "feels" stutter-y.

I suspect this could have something to do with scrolling involving integers instead of floats; which could potentially lead to stutter if things are being rounded weirdly. I'll investigate.

@adamharrison
Copy link
Member

adamharrison commented Jan 8, 2022

OK; turns out it's because time was being pushed as a whole integer, instead of with its milliseconds as decimals. Just committed directly to master to fix; should work now.

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.

4 participants