Discord
Login
Community
DARK THEME

Transpiler

The microScript language is currently interpreted in JavaScript. The performance is ok but will show some limits when you are trying to perform intensive physics calculations for example or rendering a huge number of moving objects. To improve that, I have started working on a microScript to JavaScript transpiler which I expect to be ready soon. It should bring very significant performance improvements to the engine.

The transpiler is now almost working. I still have bugs when running some projects with it (especially, it seems to have problems running Quick Engine). However I will make it available soon, in its current alpha status (as an option), so that you can check it if you want to.

I was able to run some early performance tests:

  • Raytracing demo by @this_name_is_taken: I am getting a 4x performance boost (40000 rays per second vs 10000 rays per second when interpreted)
  • My chess computer AI: 6x performance boost

Sounds great :) can't wait to tease it, haha.

Reminds me, try this one:

https://microstudio.dev/i/TinkerSmith/boids/

Never finished it ... because the speed sucks, LOL

Thanks @TinkerSmith I will look into it!

Wow, this would be great! Exactly what I was about to ask after releasing my raymarcher :).

I'm also quite curious to how intense rendering programs like raymarching and raytracing would work. Would realtime raytracing be possible...?

Edit: Just noticed the test on my raytracer - haha - a four times rendering boost is massive! I have a few projects I have that I haven't been able to release (first-person procedurally generated world, realtime raytracer) because of speed limitations. Honestly can't wait for this to come out, hopefully in time for my incoming raymarcher as well.

Also, I just found an interesting scratch feature that speeds up scratch projects by compiling them into javascript - https://turbowarp.org/ if that helps.

The transpiler is there! To activate it, open the console options and check "Use the transpiler". Then you need to relaunch your project.

Some projects will not work at all. Many projects should work though, and when they do, they should show a significant improvement in performance.

If you have publicly available projects that does not run with the transpiler, please notify me, it may help me find the remaining bugs.

To run your project full window with the transpiler, just add #transpiler to the URL, like this: https://microstudio.io/this_name_is_taken/3dplatformer/#transpiler

Ok. Wow. I used this on my raytracer in the console, and it was definitely much faster. But when I ran it in the full screen window it showed no difference in performance...?

I presume it makes no difference in embedded projects at the moment (see below).

:embed https://microstudio.io/this_name_is_taken/raytracerv1/#transpiler

:embed https://microstudio.io/this_name_is_taken/raytracerv1/

And also, the 3d platformer is definitely showing speed improvements. Time to put the transpiler link in the description ;)

Edit: Just tried this on my raymarcher. My raymarcher (which was slightly lagging at 5 samples per frame) now starts slightly lagging at 20 samples per frame. A signficant improvement!

(without transpiler)

:embed https://microstudio.io/this_name_is_taken/raymarcher/FHJE9D3D/

(with transpiler) https://microstudio.io/this_name_is_taken/raymarcher/FHJE9D3D/#transpiler

I noticed the same. The editor preview runs faster, but in full screen mode it seems to be running at it's 'old' speed.

https://microstudio.dev/i/TinkerSmith/terrain/


Edit: ... weird ... seems to be running faster on Chrome browser? Definitely slower on Firefox. Have to look into this.

@this_name_is_taken, I would like to suggest that you make the following change in your ray tracer:

update = function()
  local exit_time = system.time()+16
  while system.time()<exit_time
    ...

This way you are ensuring to use all the computing time you have available, without overstressing the CPU. This would best let us appreciate how efficient it is, with or without the transpiler. This is how I benchmarked it on my side. Possible bonus feature: count the number of samples tested and the elapsed time and display the average number of rays per second :-)

Sounds great! That would work perfectly, thanks :).

I can use that in my raymarcher as well!

Edit: Done! Seems to be working well :)

I noticed that if the secret URL is #transpiler the project doesn't load while it isn't public.

It seems that the transpiler has a problem with functions that create and return objects. Is there any way to fix this?

@Abr00 I checked a few cases and couldn't reproduce, can you give me a sample code which wouldn't be working as expected?

This was my attempt to duplicate the bug that succeded (I changed the original to avoid the bug):

createObject = function()
  obj = object
    example = function()
      var += 1
      for i = 0 to 5
        print(i)
      end
    end
    
    var = 1
    
  end
  return(obj)
end

This is what I got in the console without the transpiler:

> obje = createObject()
  object
    example = [function]
    var = 1
  end
> obje
  object
    example = [function]
    var = 1
  end

With transpiler:

> obje = createObject()
  0
> obje
  0

The obje variable appeared to be set to zero (there were no errors, but that might have been the transpiler as well). In addition, I noticed that trying to test any function in the console with the transpiler would return [native function] or 0. Functions that returned 0 didn't appear to be working properly.

Thanks for the sample code :-) however I do not get the same results as yours, very strange. For me it works with the transpiler as well as with the interpreter.

There must be something we are doing differently. Maybe make a project with just your sample code and share it with me? It would be nice to include some text output to the test code so that we can clearly see that the output is different. Like:

createObject = function()
  obj = object
    example = function()
      var += 1
      for i = 0 to 5
        print(i)
      end
    end
    
    var = 1
    
  end
  return(obj)
end

print(createObject())

But the code above seems to work correctly for me with or without the transpiler.

Interestingly, I tried out the sample code (@gilles' version) as well and these were my results:

// With transpiler
object
  example = [native function]
  var = 1
end
// Without transpiler
object
  example = [function]
  var = 1
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community