The game lagging after exported to the Web (.HTML)

Godot Version

4.1.3 / 4.2.1


So i have exported my game to the Web, and noticed a lot of lags, currently the main thing i worry about is when i just opened the game and for example pressing shoot button, it takes some time before shoot (looks like it load something, but actually not, it’s just freezes for 0.2 sec and it’s not in-code await or something!).


Generally it have a lot of freezes / lags, i would like to know how to fix it.
The lags appears only when exporting for Web.
on PC this lag seems very small (in 4.2.1 it looks exactly like in browser)

[ Browser testing (.html) ]
I’m getting 28-35 fps from 60 needed on my laptop.
Also, tested on high-res screen → 24-27 / 60 fps

[ PC testing (.exe) ]
about 59/60 fps on laptop
about 50/60 fps on high-res screen

It’s not a such big game to have such lags, it’s not even a demo, it’s just an test run.

upd. What i have noticed is when i creating the bullet (not only bullet but any node stored in var) at first time it have that lag.

@onready var hit_point = preload("res://scenes/weapons/bullets/bullet_hit.tscn")

func shoot():
   var hit = hit_point.instantiate()
   var world = get_tree().get_root()
   *lag here*

it does for me too, for the first time like first time it’s visible, it may be lagged, not in 3d game here

Have you fixed it?

i do believe it the way it works on web, same project exported for android and windows doesnt have this “first time lag” issue

you might wanna try newer version see if it’s fixed, i havent tried it, my godot version for above mentioned export was 4.1.1 stable

you are lucky because i just don’t know how to fix that, even if i’m spawning simple cube → it making lags in Web, it’s just crazy thing…

actually i have tried different versions, i always have this stuff on start…
even if i create it on start, on func _ready(), it will freeze when i need to create it manually later

that sounds bad, i assumed it’s a bug godot has now for web, might want to search if someone reported it

i have found few github issues for this topic, and seems that Godot Devs not fixing that already for very long time.

do you had this bug in godot 3?

i dont make games on godot 3, so i havent tested it

ah, seems that here no possible solution for this.

i read lighting may caused lag spike when instantiating new object inside it

i read something similar, but i’m not spawning object exactly inside the light, or you mean that way so light go through it?

i mean inside the light’s scope, but 3d needs light, so it is what it is

yep, 3d needs the light… but i have tried to delete the Light, it is not helped me

i read the workaround being instantiate it on load or already on the scene, so it doesnt appear to be lagging when on play mode shooting bullet

is there way to really pre-load all the possible/used objects on start?
because this way it is not works really well i think:
@onready var hit_point = preload("..")
in my opinion the code above must load the assets when game loading, but it works other way, and it’s sad

how about
@onready var bullet=preload("res://bullet.tscn").instantiate()
so just need add child later

but this

it does lag after adding child, interesting

yep, i have tried this way too. unfortunately the same result

just want to remind that i have other lags, not only on object creating, and it’s up to Godot, because i dont have such heavy things on the scene.

also, i tried to change Project Settings, but nothing helped me

yeah, godot’s issue
i wanted to recommend other engine that’s far better just for making web games, but i dont think it’s allowed here lol

i merely using export to web just for easily accessible way of testing for many people, but not building actual game for web which godot’s web is not optimized. Memory Usage alone took over 220mb on chrome to run a single label project. other engine can do it less, a playable snake game with particles only needs on average 50mb space to run

I think i just need to find a way out of these lags, because changing engine is not an option for me actually. For example, Unity have very long and stressful loading/import and C# as main language which i hate as well.
So for now i will choose Godot, but not because it’s worth it, but because I’ve already come a very long way in developing my game on it.

Unfortunately, its developers are focusing on the the wrong things.
The most valuable thing is performance, which is smells bad in godot.

There was Construct 2 Engine that was like a god stuff for developing HTML games, but it supports making only 2D games, so what i want to say is i want Godot should be similar to Construct 2 but instead 2D made focus on 3D.