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
You don't mind every single possible optimization right? #1
Comments
See update below |
Buffering exist exactly for that reason. Yeah that will affect performance
if you turn off buffering, but in most cases buffering is turned on by
default.
Pada tanggal Jum, 5 Feb 2021 03.51, VADemon <notifications@github.com>
menulis:
… Don't concat when passing string to io.write. io.write accepts arbitrary
arguments which has same effect as concatention
Except under the hood in standard Lua, io.write() makes a system call for
each argument instead of concatenation. That's slower, especially on Intel
CPUs and the endless security patches.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABZHFFXW4MZOK6ZQ4EZJRYTS5L3FZANCNFSM4XC3SZMQ>
.
|
I concur, Lua does a call to "Octuple" =
|
If so, then read along.
cs2drecorder/Recorder/GameReplay.lua
Line 42 in eb1ca1a
io.write
.io.write
accepts arbitrary arguments which has same effect as concatention, so you can doio.write(tostring(timeStamp), " = ", state:ToString())
instead.cs2drecorder/Recorder/GameReplay.lua
Line 59 in eb1ca1a
cs2drecorder/Recorder/GameReplay.lua
Lines 92 to 113 in eb1ca1a
strWrite
be table and for every string you want to add, append into the table withstrWrite[#strWrite + 1] = str
. Then when writing, doio.write(table.concat(strWrite))
. Those string concatenation can be expensive (both in terms of performance and memory) oncestrWrite
is large.cs2drecorder/Recorder/GameState.lua
Lines 20 to 37 in eb1ca1a
table.concat
.cs2drecorder/Recorder/Assembler.lua
Lines 18 to 24 in eb1ca1a
cs2drecorder/Recorder/Addhooks.lua
Line 82 in eb1ca1a
pairs
.As a side note: Files opened with
io.open
is buffered by default. It's usually okay to left the buffer setting as-is, but if you want (which may or may not impact performance), you can set the buffering mode withfile:setvbuf
.The text was updated successfully, but these errors were encountered: