ChatPatches icon indicating copy to clipboard operation
ChatPatches copied to clipboard

Save log on thread other than render thread

Open layou233 opened this issue 8 months ago • 4 comments

Is your feature request related to a problem? Please describe.

[22:40:03] [Render thread/INFO]: [ChatLog.serialize] Saving...
[22:40:07] [Render thread/INFO]: [ChatLog.serialize] Saved the chat log containing 11236 messages and 108 sent messages to '<>/logs/chatlog.json' in 4.026 seconds

So my game was frozen for 4.026 seconds.

Describe the solution you'd like Use a seperate thread instead of render thread to save logs.

Describe alternatives you've considered ForkJoinPool.commonPool().execute()

Additional context I've created a workaround in my fork: https://github.com/layou233/ChatPatches/commit/32ea2639693d881eaa10a68e1cbb1ace7e8e990e However, this ignores data race conditions, and I think concurrent safety issues should be considered. I'm not familiar with this mod, so opening an issue here. :)

layou233 avatar Apr 19 '25 06:04 layou233

thanks for the report! to be honest i know next to nothing about multithreading in java, so i'll have to do some research before i implement this to avoid any fatal errors. but i will definitely keep this in mind when deep diving! in the meantime, perhaps consider trimming some of those 11k messages?

mrbuilder1961 avatar Apr 19 '25 07:04 mrbuilder1961

Sometimes it's not the size of the text that's causing the long pauses because I/O operations are really unpredictable. It could be a bottleneck on the hard drive, anti-virus software, or a bad Windows kernel update. So if no one else reports the same issue, I think we can put it on hold until it's fully fixed. In the meantime I can use my fork and look for a solution. Thanks for your work!

layou233 avatar Apr 19 '25 08:04 layou233

https://github.com/layou233/ChatPatches/commit/d1a2488345e48a7e8bc1f5e7b7ca555d1e8751cb

Based on my last commit. My idea is to synchronize list operations and copy on serialization.

layou233 avatar Apr 19 '25 10:04 layou233

i like these ideas, i've implemented the synchronized part in the dev-stage omnivers branch, but i'm still trying to find the best way to queue the tasks to be executed, as minecraft does interact with threads quite a bit behind the scenes. i have a few potential candidates so when i can i will look into those!

mrbuilder1961 avatar May 02 '25 18:05 mrbuilder1961

impl'd this in the in-dev omnivers branch, if you'd like to take a look yourself. it's currently only available in 1.20.2 but will expand to newer versions soon (:

mrbuilder1961 avatar Jun 23 '25 00:06 mrbuilder1961

Didn't notice the Minecraft IO pool thread, it's great!

Haven't tried yet but the code LGTM. 🥰

layou233 avatar Jun 23 '25 08:06 layou233

implemented in 8.0-alpha.1!

mrbuilder1961 avatar Jul 18 '25 16:07 mrbuilder1961