Skript Version: skUtilities.v0.9.2
Skript Author: tim740
Minecraft Version: 1.12
---
Full Code:
Note: If the code is too large, feel free to use a pasting website (Pastebin or hastebin)
Note: If a variable is being set in another script, but not shown, please explain how they are being set
The point is, it works fine, until there's about 30kbs worth of logs in the txt file. In which point, the server freezes for about 1 tick just to log the string.
It get's out of hand when the size gets over 100kb, which happens since there's a lot of mob hunting in my server.
I noticed through examining the log files while the server was writing stuff on it, that obviously SKUtilities was reading the whole txt file and adding a line, and then rewriting - which explained why bigger files were lagging the server.
Here's the source code of where this is happening
skUtilities-master\src\uk\tim740\skUtilities\files\EffInsertLine.java
I'm not an expert in file IO, but I thought that a simple "append" function would have
done the trick.... but instead the source code apparently reads the whole txt file
and rewrites the whole text file in order to append one line.
I'm not sure if this is the right place to ask for this
but can anyone fix that part so that it doesn't lag with big txt files?
Addons using (including versions):
Pretty sure other addons are irrelevant
Troubleshooting:
Have you tried searching the docs? Yes
Have you tried searching the forums? Yes
What other methods have you tried to fix it? I tried rewriting the part of code myself with the github source code - only to find that the source code I recompiled myself threw errors on certain expressions(probably because I'm not too familiar with plugin development)
Skript Author: tim740
Minecraft Version: 1.12
---
Full Code:
Note: If the code is too large, feel free to use a pasting website (Pastebin or hastebin)
Note: If a variable is being set in another script, but not shown, please explain how they are being set
code_language.skript:
function Log(logFile:string,log:string):
set {_str} to "%formattedTime()% %{_log}%"
add {_str} to {log::*}
add {_logFile} to {log.file::*}
every 5 ticks: #This stuff in case multiple mobs are killed at once -> spread out the load
loop {log::*}:
write {log::%loop-index%} at line {%{log.file::%loop-index%}%.line} to file {%{log.file::%loop-index%}%}
add 1 to {%{log.file::%loop-index%}%.line}
delete {log::%loop-index%}
delete {log.file::%loop-index%}
exit loop
The point is, it works fine, until there's about 30kbs worth of logs in the txt file. In which point, the server freezes for about 1 tick just to log the string.
It get's out of hand when the size gets over 100kb, which happens since there's a lot of mob hunting in my server.
I noticed through examining the log files while the server was writing stuff on it, that obviously SKUtilities was reading the whole txt file and adding a line, and then rewriting - which explained why bigger files were lagging the server.
Here's the source code of where this is happening
skUtilities-master\src\uk\tim740\skUtilities\files\EffInsertLine.java
Code:
try {
ArrayList<String> cl = new ArrayList<>();
cl.addAll(Files.readAllLines(pth, Charset.defaultCharset())); //<========= right here!!!
for (Number cn : line.getAll(e)) {
if ((cn.intValue() -1) > cl.size()) {
Integer dn = ((cn.intValue() -1) -cl.size());
for (int n = 0; n < dn; n++) {
cl.add("");
}
}
cl.add(cn.intValue() - 1, txt.getSingle(e));
}
Files.write(pth, "".getBytes());
for (String aCl : cl.toArray(new String[cl.size()])) {
Files.write(pth, (aCl + "\n").getBytes(), StandardOpenOption.APPEND);
}
}
I'm not an expert in file IO, but I thought that a simple "append" function would have
done the trick.... but instead the source code apparently reads the whole txt file
and rewrites the whole text file in order to append one line.
I'm not sure if this is the right place to ask for this
but can anyone fix that part so that it doesn't lag with big txt files?
Addons using (including versions):
Pretty sure other addons are irrelevant
Troubleshooting:
Have you tried searching the docs? Yes
Have you tried searching the forums? Yes
What other methods have you tried to fix it? I tried rewriting the part of code myself with the github source code - only to find that the source code I recompiled myself threw errors on certain expressions(probably because I'm not too familiar with plugin development)