[HN Gopher] Using TS type annotations for JavaScript engine opti...
___________________________________________________________________
Using TS type annotations for JavaScript engine optimization
Author : canadahonk
Score : 18 points
Date : 2024-01-26 12:07 UTC (2 days ago)
(HTM) web link (goose.icu)
(TXT) w3m dump (goose.icu)
| rezonant wrote:
| > But since we are compiling AOT and not JIT, we cannot de-
| opt/undo that guess if it becomes wrong - instead we would just
| crash. > > But we could define the type using type annotations
| (TS)! > > Now we have to do 0 checks of the type of a, since we
| already know it at compile-time. This can allow for some big
| speedups :)
|
| This comes with a big caveat that if the type assertion is wrong
| at runtime that the AOT'ed app will crash. Also I get the sense
| that the author assumes type "string" always means non-null and
| non-undefined but this is only true if the strictNullChecks
| compiler option is enabled.
|
| Nonetheless, cool to see folks experimenting in the JS engine
| arena, especially around AOT!
| o11c wrote:
| A useful way to think of this kind of thing is to hoist the
| assertions into the caller, where they can be optimized out.
|
| There's a lot of poorly-explored room in compiler design to
| take generalized invariants/preconditions/postconditions into
| consideration (explicit ones are useful for opaque functions
| defined in a different TU), not just things considered "types"
| (the problem with types is that they have different
| lifetime/allocation concerns than assertions).
| ReleaseCandidat wrote:
| Refinement types and liquid types (which are a subclass of
| refinement types).
| thaodsfwefs wrote:
| > Disabling `strictNullChecks`
|
| Are people this eager to be PIP'd?
| h4ch1 wrote:
| Just a hitch found on https://porffor.goose.icu/
|
| On running the example 'Array Reading' with an optimization level
| of 3 I get the following error
|
| CompileError: WebAssembly.instantiate(): Compiling function #2
| failed: local.set[0] expected type f64, found global.get of type
| i32 @+207
|
| Is this expected?
___________________________________________________________________
(page generated 2024-01-28 23:01 UTC)