I'm probably posting this in the wrong section. Moderators, please move it to the appropriate one if it's not in the right place.
So basically, I am experiencing this problem each time I open Minecraft for the first time, ever since I started playing the game last year.
Every time I perform a task such as hitting a specific mob, or breaking/placing a specific block, I get a lag spike (probably while playing the sound of that specific task.) I no longer get lag spikes once the game "gets used" to said task.
No matter I use OptiFine or not, I get the exact same problem.
Has anyone experienced this before? And yeah, it may sound weird to you...
PC specs (it's a laptop from the 2007-2008 days, sigh...):
HP Pavilion dv6000 dv6700 Notebook PC
4GB RAM DDR2
Intel Core 2 Duo @2.00 GHz
Ubuntu 18.04 LTS amd64
All I can think of for the moment.
PS: No replies such as "Your PC is old, get a new one", "Laptops weren't made for gaming" or "Dont use HP laptops because they have serious cooling problems" Because I already know that. The matter is that my parents don't have the money for a decent one, so I'm just sticking around with this 10-11 year old laptop...
Not sure of what's happening but are you using the Java provided by Ubuntu or another one?
Try changing the Java used because it can be a problem which regards the sound driver, installing Oracle Java in case you're using openjdk packaged by Ubuntu or the other way around (I don't know if there could be pulseaudio issues with Java).
No, I’m using the Java provided by Oracle. (Java 8)
Edit: After a bit of searching, I think I found the solution to this problem. People suggest replacing the OpenAL files to fix sound lags. I could try that, but seeing as I cannot use my PC right now because of my exams, that will have to wait until next Thursday...
I don't think it's a hardware issue despite the age of it since it seems to only have the issue the first (?) time something occurs. It sounds like once something is cached it's not having the issue, and/or something is causing it to perform bad when it's not cached. It COULD be the video card and/or drivers for something (or Java itself), but the CPU and RAM while older now shouldn't be causing that (have a few Core 2 Duos friends still use in Minecraft, and while they show their age in later versions at higher render distances, they are very playable, but I'm not too familiar with Linux).
You say this been an issue for more or less a year? I'm going to guess this means it occurs across a range of Minecraft versions, and potentially Java versions too. Have you changed your video drivers during that time?
The way that Java works is that it will only load classes as their code is executed, which can cause a lag spike as it stops to load them from disk, and executes it in interpreted mode for a certain number of runs before it complies it into native code, before which it will be much slower (some code may never be compiled at all, saving time by not having to compile it; the time taken for performance to reach its maximum is call "warm-up" time and is characteristic of modern JVMs). Likewise, aside from block/item textures the game loads assets like sounds and other textures as they are needed, which again can cause lag spikes (once they are loaded they will remain loaded until you quit the game so this will cause one-time lag spikes).
I've never really noticed this, aside from the first time I generate new chunks in a play session, which often causes a brief lag spike, likely due to the JVM having to load and initialize a considerable amount of code (this is most likely due to the JVM itself as server-side lag should not affect the client on a multi-core PC; I've even written test code when developing mods that totally locked up the server for minutes yet the client never froze other than server-controlled things like entities not moving). Conversely, code that is executed often, like rendering code and block tick logic, is loaded as soon as the game is launched and/or a world is loaded and stabilizes within as little as a single frame so you'll never notice the warm-up time.
Also, any advice to replace some files is obsolete (the instructions here are referring to a "bin" folder, meaning the pre-1.6 launcher which cannot run any version newer than 1.5.2, if it can even still log in) and will not work without significant modifications or other work-arounds (the current launcher will simply replace any files that are altered), plus they use a different version of the OpenAL library in 1.13 than earlier versions so if both 1.13 and older versions have the issue it is unlikely to be related (the older library is bugged in a different way, causing the game to sometimes start with no sounds or even crash with a fatal JVM error as it started doing for me; I did replace it myself with a newer library by downloading the file from the LWJGL site, placing it in a location other than the game files, and adding a JVM argument to point to it (see comments here) but this is unlikely to fix your issue since it is likely caused by the game having to load the file and other stuff as mentioned above, which is why it goes away after a while).