How can I jit-compile a program that runs in a loop? - dart

I have a web listener written in dart. I want to start it quicker, thats how I found https://dart.dev/tools/dart-compile#jit-snapshot.
However, when I execute dart compile jit-snapshot server.dart it runs the code which will run forever and so I never get the server.jit file. When I close the web-listener after a couple seconds it works fine but thats not what i want to compile.
Dart SDK version: 2.19.0-424.0.dev (dev) (Wed Nov 23 07:45:20 2022 -0800) on "linux_arm64"
dart compile jit-snapshot server.dart
should: generate server.jit
does: run forever. When I cancel it with Ctrl+c the .jit file is not generated...

For best performance, use AOT compilation
dart compile aot-snapshot server.dart
or build an executable
dart compile exe server.dart

Related

dartdevc improving build speed with reuse of kernal/dill files

I'm using the Dart Dev Compiler (ddc / dartdevc) to convert some Dart files to JavaScript. All is working as expected, however the build times are somewhat slow (3 seconds or so).
The CLI for DDC allows the passing of a "summary" file, which from research looks to be the kernal/.dill files for Dart. I'm not entirely sure what these are, but from looking around at implementations such as DartPad and the webdev package, providing this file seems to be the way forwards.
I can successfully provide my local copy of the ddc_sdk.dill file, and the build does compile file, however the speed is still slow. DDC also generates a .dill file for the generated JavaScript file, however I'm not entirely sure what it's for, or what the use of it is.
Providing the generated .dill file throws the error:
dartdevc -k arguments: -s /example/.dart_tool/js/test.dill --packages /example/.dart_tool/package_config.json -o js/test.js /example/test.dart
dart --version: 2.17.0-222.0.dev (dev) (Fri Mar 18 12:54:18 2022 -0700) on "macos_x64"
Crash when compiling org-dartlang-app:/js/test.dart,
at character offset null:
Null check operator used on a null value
#0 _buildInternal (package:front_end/src/kernel_generator_impl.dart:129:53)
Essentially I have a ./dart_tool/js/test.dart file, and I execute:
dartdevc
--summary
./dart_tool/js/test.dill
--packages
./dart_tool/package_config.json
--output
./dart_tool/js/test.js
./dart_tool/js/test.dart
Can anyone shed any light on how to speed up builds with DDC & reuse the .dill files?

Executing Dart File takes too long

As a newbie in dart dev , I starting by setting up my VS Code for Dart/Flutter .
When I try to run a simple Dart program ( just to check everything works fine printing sum of 2 int 4+6 )
PS B:\Flutter> dart .\Sum_Course_Exemple.dart
'git' is not recognized as an internal or external command,
operable program or batch file.
Building flutter tool...
Running pub upgrade...
4+6=10
These lines takes too long to show the output .
Am I doing something wrong ? why it's taking 3min to show that output for a simple code ?
Either Flutter or pub is trying to install or upgrade dependencies, but this relies on Git, which you do not have installed.
As a result, the Flutter SDK tries to perform some first-run initialisation every time you run your program, which is why it takes so long each time.
Git can be obtained from its website.

Load/Recompile Rebar Modules after downgrading Erlang/OTP

I wish to use an erlang client library to communicate with an mqtt broker for one of my projects. So I've started an application using rebar3's built-in templates and added emqttc as a dependency. Since erlang/otp 21 does not have support for gen_logger(emqttc depends on gen_logger) and the tuple_calls compiler options do not suffice, I had to downgrade to erlang#20 according to this post.
Now the issue with downgrading erlang is that, none of rebar3's commands(clean/compile/shell/report etc) work as expected and my previous projects built with rebar3 do not compile, I get to see this error message:
=ERROR REPORT==== 21-Aug-2018::12:54:29 === Loading of /usr/local/bin/rebar3/rebar/ebin/rebar3.beam failed: badfile escript:
exception error: undefined function rebar3:main/1 in function
escript:run/2 (escript.erl, line 759) in call from escript:start/1
(escript.erl, line 277) in call from init:start_em/1 in call from
init:do_boot/3
=ERROR REPORT==== 21-Aug-2018::12:54:29 === beam/beam_load.c(1863): Error loading module rebar3: This BEAM file was compiled for a later
version of the run-time system than 20. To fix this, please
recompile this module with an 20 compiler. (Use of opcode 160; this
emulator supports only up to 159.)
I've uninstalled and reinstalled rebar3, looked up on the web for this but nothing's clear and specific to rebar. Any help on this would be appreciated.
This may not be the exact answer for your question. But it may give you and idea.
What about using Docker. Its an easy way to keep your environment clean and neat.
If you use docker, you just have to include your new erlang version in Dockerfile as an environment variable.
ENV OTP_VERSION="20.3.6"
Check your _build/prod/rel/YOURAPPNAME/ directory. Most probably it has a release which doesn't match your erlang version. You can safely delete this directory and rebuild using rebar3 compile

What does 'pub run' differs from normal execution?

I find there are some differences that I can't figure out which nor how when executing a binary withpub run bin_executable.dart args rather than dart bin/bin_executable.dart args.
Execution is notably slow in the first form, and the output is worst, sometimes erroneous...
I searched here but didn't find anything useful. Any help?
pub run bin_executable.dart runs pub, and pub starts an new process that runs dart bin_executable.dart
There was a recent change that allows pub to run bin_executable.dart in a new Dart isolate instead of a new process. That might make it a little faster but I think the main purpose is to allow to attach a debugger to debug bin_executable.dart when run with pub (especially for pub run test)
I assume the main part or the slower execution is the start time for pub

dart:uri in generated Dart html pages does not run

With the latest version of dart (editor 24275) I keep getting an error re: dart:uri
This is placed in my built html:
import "dart:isolate" as FB;import "dart:uri" as MH;import "dart:json" as ............
Dart VM version: 0.5.20.4_r24275 (Fri Jun 21 05:02:35 2013) on "macos_ia32"
dart:uri is now in dart:core I recall.. but my html keeps getting built with this in it and so doesn't run in Chromium with the Dart VM
I've removed the out folder and rebuilt, does not resolve it.
Have you definitely removed all instances of import "dart:uri" from your code, whether they are stand alone Dart scripts or scripts embedded in HTML templates/components etc?
It's always good to run "Reanalyze Sources" too.
It sounds like you need to run pub update.

Resources