# Slowdown on different plattforms (SOLVED)

**URL:** <https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117>\
**Category:** Bugs\
**Created:** [October 5, 2016, 10:35am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117 "2016-10-05T10:35:34Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Almitt](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@Almitt](https://forum.defold.com/u/Almitt)\
**Post date:** [October 5, 2016, 10:35am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/1 "2016-10-05T10:35:34Z")

</div>

Since my other issue were (partially) solved so quickly by you guys, i have yet another mystery for you.

I’m developing on a linux computer using the 64-bit editor. The project is working as intended on this setup. However, when i swap to my PC at home (running 64-bit windows and the windows editor) the game is significantly slower. As in roughly a third of the speed.  
The same thing happens if i compile to HTML on my Linux (that runs the game perfectly normally).  
No settings are changed between the runs.  
What could cause this issue?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 5, 2016, 12:10pm UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/2 "2016-10-05T12:10:47Z")

</div>

I would start by [checking the profiler](http://www.defold.com/manuals/debugging/#_web_profiler). Could it be that your Linux machine has more power and is able to churn out 60 fps while your Windows machine and browser isn’t able to keep up?

---

<div class="post-metadata">

**Author:** ![Almitt](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@Almitt](https://forum.defold.com/u/Almitt)\
**Post date:** [October 5, 2016, 12:18pm UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/3 "2016-10-05T12:18:50Z")

</div>

My Linux machine (being a laptop) is significantly slower then my Windows machine. The profiler doesn’t show any kind of congestion issues.  
Another rather interesting effect effect of the issue is that the script controlling my character (that i made work with my last topic…) seems to break as well. In a rather interesting way…  
I am able to do about half of my actions, but moving right does not work.  
Most of the things that seem to malfunction are numerical calculations, is it possible that the 64-bit editor just simply doesn’t translate well when compiled with 32-bit?

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 5, 2016, 12:31pm UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/4 "2016-10-05T12:31:50Z")

</div>

No, there is no difference in compilation. If you experience behavioral differences it’s likely some errors in your script(s) that somehow manifest themselves differently on the platforms. It would be very interesting to run some tests ourselves. Do you have a minimal example that you can post?

---

<div class="post-metadata">

**Author:** ![Almitt](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@Almitt](https://forum.defold.com/u/Almitt)\
**Post date:** [October 5, 2016, 12:35pm UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/5 "2016-10-05T12:35:25Z")

</div>

The entirety of the script controlling my character (mostly based on the tutorialscript):  
If there is indeed an error in a script that is causing this, it should be in there.  
The game itself is also rather minimal, as i’ve just started out. It would be hard to post it though.

```lua

local move_acceleration = 5
local air_acceleration_factor = 0.8
local max_speed = 15
local gravity = -7
local jump_takeoff_speed = 50

-- pre-hashing ids improves performance
local msg_contact_point_response = hash("contact_point_response")
local msg_animation_done = hash("animation_done")
local group_Ground = hash("Ground")
local group_Walls = hash("Walls")
local group_Breakable = hash("Breakable")
local input_left = hash("Left")
local input_right = hash("Right")
local input_jump = hash("Jump")
local input_rush = hash("Rush")
local input_glide = hash("Glide")
local animation_done_message = hash("animation_done")

function init(self)
    msg.post(".", "acquire_input_focus")
    self.velocity = vmath.vector3(0, 0, 0)
    self.correction = vmath.vector3()
    self.ground_contact = false
    self.move_input = 0
    self.anim = nil
    self.hit_roof = false
    self.face_left = false
    self.rushing = false
    self.gliding = false
    self.animating = false
    print("finished init")
end

function update(self, dt)
	if self.face_left then
		sprite.set_hflip("#sprite", true)
	else
		sprite.set_hflip("#sprite",false)
	end
	msg.post("camera","look_at",{ position = go.get_position()})
    local target_speed = self.move_input * max_speed
    local speed_diff = target_speed - self.velocity.x
    local acceleration = vmath.vector3(0, gravity, 0)
    if self.gliding and self.velocity.y <= 0 then
    	acceleration.y = acceleration.y/9
    end
    if speed_diff ~= 0 then
        if speed_diff < 0 then
            acceleration.x = -move_acceleration
        else
            acceleration.x = move_acceleration
        end
        if not self.ground_contact then
            acceleration.x = air_acceleration_factor * acceleration.x
        end
    end
    local dv = acceleration * dt
    if math.abs(dv.x) > math.abs(speed_diff) then
        dv.x = speed_diff
    end
    local v0 = self.velocity
    self.velocity = self.velocity + dv
    if self.rushing then
    	if self.face_left then
    		self.velocity.x = -max_speed-10
    	else
    		self.velocity.x = max_speed+10
    	end
    end
    local dp = (v0 + self.velocity) * dt * 0.5
    go.set_position(go.get_position() + dp)
    self.correction = vmath.vector3()
    self.move_input = 0
  	if self.gliding and not self.ground_contact then
   		msg.post("#sprite","play_animation",{id = hash("Gliding")})
  	elseif self.rushing then
  		msg.post("#sprite","play_animation",{id = hash("Rushing")})
  	else
  		local moving = not (self.velocity.x == 0) and not (self.gliding or self.rushing)

    	if moving and not self.animating then
   			msg.post("#sprite", "play_animation", {id = hash("Running")})
   			self.animating = true
   		elseif not moving and not self.animating then
   			msg.post("#sprite","play_animation", {id = hash("Idle")})
   		end
 	end	
 	self.ground_contact = false
end

local function handle_obstacle_contact(self, normal, distance)
    local proj = vmath.dot(self.correction, normal)
    local comp = (distance - proj) * normal
    self.correction = self.correction + comp
    go.set_position(go.get_position() + comp)
    if normal.y > 0.7 then
        self.ground_contact = true
        self.gliding = false
    end
        proj = vmath.dot(self.velocity, normal)
    if proj < 0 then
       self.velocity = self.velocity - proj * normal
    end
end

function on_message(self, message_id, message, sender)
    if message_id == msg_contact_point_response then
        if message.group == group_Ground or message.group == group_Walls then
            handle_obstacle_contact(self, message.normal, message.distance)
        elseif message.group == group_Breakable then
        	if self.rushing then
        		msg.post(message.other_id,"destroy_self")
        	else 
        		handle_obstacle_contact(self, message.normal, message.distance)
        	end
    	end
	end
	if message_id == animation_done_message then
		self.animating = false
	end
end

local function jump(self)
    if self.ground_contact then
        self.velocity.y = jump_takeoff_speed
    end
end

local function abort_jump(self)
    if self.velocity.y > 0 then
        self.velocity.y = self.velocity.y * 0.5
    end
end

function on_input(self, action_id, action)
    if action_id == input_left then
        self.move_input = -action.value
        self.face_left = true
        self.rushing = false
    elseif action_id == input_right then
        self.move_input = action.value
        self.face_left = false
        self.rushing = false
    elseif action_id == input_jump then
        if action.pressed then
            jump(self)
        elseif action.released then
            abort_jump(self)
        end
    elseif action_id == input_rush then
    	self.rushing = true
    elseif action_id == input_glide then
    	if not self.ground_contact and action.pressed then
    		self.gliding = not self.gliding
    	end
    end
end

```

---

<div class="post-metadata">

**Author:** ![Almitt](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@Almitt](https://forum.defold.com/u/Almitt)\
**Post date:** [October 5, 2016, 12:46pm UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/6 "2016-10-05T12:46:51Z")

</div>

if you would like the entirety of the game to do tests, i’ll happily provide it in any form that would be suitable.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 5, 2016, 6:35pm UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/7 "2016-10-05T18:35:03Z")

</div>

You can add me ([bjorn.ritzl@king.com](mailto:bjorn.ritzl@king.com)) and Mikael ([mikael.saker@king.com](mailto:mikael.saker@king.com)) as team members from the dashboard. Once we’re added we will be able to access the project and do some tests. Don’t forget to sync your project!

---

<div class="post-metadata">

**Author:** ![Almitt](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@Almitt](https://forum.defold.com/u/Almitt)\
**Post date:** [October 5, 2016, 6:47pm UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/8 "2016-10-05T18:47:30Z")

</div>

There, I have added you.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 6, 2016, 7:35am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/9 "2016-10-06T07:35:20Z")

</div>

Thanks,

Looking at the project it’s a bit hard to see how it’s supposed to play. I had to multiply all constants (acceleration, speeds etc) by 100 to get the character moving reasonably. Do you have unsynched stuff on your machine.

---

<div class="post-metadata">

**Author:** ![Almitt](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@Almitt](https://forum.defold.com/u/Almitt)\
**Post date:** [October 6, 2016, 7:38am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/10 "2016-10-06T07:38:31Z")

</div>

No, i’ve synced everything. And that is the problem. Playing the same game with the same code on my Linux distro runs at a “normal” speed, but i experience the same thing as you do when i swap to another machine or use the HTML-build.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 6, 2016, 7:42am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/11 "2016-10-06T07:42:25Z")

</div>

But you have a max speed of 15 IIRC and that’s like half a tile per second. Isn’t that very slow? A much more reasonable speed for a platformer would, with the size and scale of your game, be ~100 pixels per second or something like that.

---

<div class="post-metadata">

**Author:** ![Almitt](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@Almitt](https://forum.defold.com/u/Almitt)\
**Post date:** [October 6, 2016, 7:44am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/12 "2016-10-06T07:44:15Z")

</div>

But increasing that number makes the game incredibly quick on my Linux distro, which is what i mainly develop on.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 6, 2016, 7:47am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/13 "2016-10-06T07:47:45Z")

</div>

Ah, then there might be a problem with the vsync.

If you print dt in update:

```
function update(self, dt)
    print(dt)
    ....

```

What value do you get?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 6, 2016, 7:52am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/14 "2016-10-06T07:52:13Z")

</div>

Here’s a discussion around too fast update speeds: [Why is the update speed too fast? (DEF-1785) (SOLVED) - #16 by vaal](https://forum.defold.com/t/why-is-the-update-speed-too-fast-def-1785/1635/16)

---

<div class="post-metadata">

**Author:** ![Almitt](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@Almitt](https://forum.defold.com/u/Almitt)\
**Post date:** [October 6, 2016, 8:12am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/15 "2016-10-06T08:12:27Z")

</div>

I get 0.016666667535901 when i print dt.  
I think i have found a solution though. Setting the “variable dt” setting in project slowed my game down to about the speed that the Windows setup runs it on. I should have tried that earlier (in fact, i am fairly certain i did).  
The “missing functionality” of the html part was due to me running a vim enhancement for my browser, rebinding the movement keys to other stuff.

Thank you for the help!

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 7, 2016, 7:26am UTC](https://forum.defold.com/t/slowdown-on-different-plattforms-solved/3117/16 "2016-10-07T07:26:59Z")

</div>

Ok, great! I’m happy to hear that you figured it out!
