Pathfinding is causing lag

Godot Version

4.2.1

Question

My game suddenly started lagging a lot. When I checked with the profiler it said that the physics process of my enemy is causing the lag.
The Physics process only contains the pathfinding.
I have about 10 - 20 enemies spawned at a time.
Usually it starts lagging when the enemies are off screen. When I get closer so that all the enemies are visible on screen it stops lagging.

Any idea on what Im doing wrong?

func _physics_process(delta):
	var direction = Vector3()
	direction = nav.get_next_path_position()- global_position
	direction = direction.normalized()

	
	velocity = velocity.lerp(direction * speed, accel  * delta)
		
	
	move_and_slide()
	
func _on_nav_timer_timeout():
	nav.target_position = player.get_global_position()