News for hackers. Stuff that matters.
Re:Tips for Performant TypeScript by tantalor on Tuesday November 24, 2020 @10:22AM (#25199239)
Well, of course not. You can't "run" TypeScript.
Re:Tips for Performant TypeScript by karmakaze on Tuesday November 24, 2020 @10:30AM (#25199307)
No--but certain constructs could translate to slower than expected execution speed.
Re:Tips for Performant TypeScript by cogman10 on Tuesday November 24, 2020 @11:03AM (#25199618)
That's something that needs proof from a profiler. Intuition on what's "slower" is really awful, particularly for JITed languages.

I don't think you could give general advice on what is slower as that's a constantly moving target.

Re:Tips for Performant TypeScript by not_kurt_godel on Tuesday November 24, 2020 @12:08PM (#25200419)
If TS could compile to asm.js you certainly could. (The fact that it can't is a big reason why I believe it's a fundamentally bad solution to writing JS scaleably.)
Re:Tips for Performant TypeScript by tantalor on Tuesday November 24, 2020 @01:09PM (#25201125)
I think you mean Wasm; asm.js is dead.

Looks like assemblyscript compiles "a strict variant of TypeScript" directly to Wasm:

https://github.com/AssemblyScript/assemblyscript

This is pretty close to "running" TypeScript.

Re:Tips for Performant TypeScript by not_kurt_godel on Tuesday November 24, 2020 @02:01PM (#25201745)
I tend to refer to asm.js and wasm interchangeably, but yes, wasm would be the technically preferable term.

Never heard of AssemblyScript, but yeah, it or a statically typed language like it is where frontend development needs to go. In concordance with my point about TS being fundamentally unsuitable, the AssemblyScript docs (https://www.assemblyscript.org/basics.html#strictness) say:

> WebAssembly is fundamentally different from JavaScript, ultimately enabling entirely new use cases not only on the web. Consequently, AssemblyScript is much more similar to a static compiler than it is to a JavaScript VM. One can think of it as if TypeScript and C had a somewhat special child.

> Unlike TypeScript, which targets a JavaScript environment with all of its dynamic features, AssemblyScript targets WebAssembly with all of its static guarantees, hence intentionally avoids the dynamicness of JavaScript where it cannot be compiled ahead of time efficiently.

Re:Tips for Performant TypeScript by staticassertion on Tuesday November 24, 2020 @10:58AM (#25199573)
You can't "run" C, or Go, or Javascript, etc.
Re:Tips for Performant TypeScript by the_af on Tuesday November 24, 2020 @12:33PM (#25200720)
I think the parent comment meant that typescript is a static checker, which means it's not exercised at run time but in a prior step. Therefore "performant typescript" means to shorten the time it takes to perform these static checks, not the time it takes to run your code. In contrast, when people talk about optimizing C code they most often (but not always, of course) mean to write code that runs fast.
Re:Tips for Performant TypeScript by ragnese on Wednesday November 25, 2020 @02:59PM (#25213589)
I find the mentality around TypeScript to be bizarre.

"It's just a type checker for JavaScript" - not really. It's a language that transpiles to JavaScript and it happens to be a superset of JavaScript (namespaces and enums, anyone?).

But saying that it's just a layer on top of JavaScript sounds like saying C++ is just a layer on top of C.

Re:Tips for Performant TypeScript by the_af on Wednesday November 25, 2020 @04:59PM (#25214757)
> C++ is just a layer on top of C

C++ used to be just a layer on top of C, but not anymore. If it still was, it wouldn't be a bad thing to say.

Type checks that run during compilation/transpilation/typechecking do not "run" as the code is executed. This is what happens with Typescript, and that's what the original commenter was saying.

Re:Tips for Performant TypeScript by choward on Wednesday November 25, 2020 @04:12PM (#25214345)
I'm not sure I understand your point. Typescript is a language with a type checker and compiler. It's the same thing with C. Typescript has to be compiled to run. C has to be compiled to run. When I think of language performance I always default to thinking about runtime performance.
Re:Tips for Performant TypeScript by the_af on Wednesday November 25, 2020 @04:56PM (#25214727)
> I'm not sure I understand your point.

When people talk about C performance, they mean the performance of the code written in C and (ultimately) compiled to machine language. Very seldom they mean the speed of compilation (though they sometimes do, in which case they almost always explicitly mention "compilation").

When people talk about Typescript performance, they either mean Javascript performance or, more likely, the speed with which Typescript type-checks their code; the latter doesn't happen in run time. That's what the original commenter meant when they said "you cannot run Typescript". It's also what TFA means by "performant".

Re:Tips for Performant TypeScript by arc0 on Tuesday November 24, 2020 @10:30AM (#25199314)
Deno[0] supports running TypeScript without needing to compile it to JS.

[0] -- https://deno.land/

Re:Tips for Performant TypeScript by nicoburns on Tuesday November 24, 2020 @10:31AM (#25199330)
Deno still compiles it to JS. It just does it for you.
Re:Tips for Performant TypeScript by capableweb on Tuesday November 24, 2020 @12:13PM (#25200480)
Which at one point gets compiled to machine code. At one point, you have to stop and say, "Yeah, this does effectively runs TypeScript", otherwise as I said, you'll end up saying nothing gets run but machine code. While that's correct, not very useful.
Re:Tips for Performant TypeScript by nicoburns on Tuesday November 24, 2020 @12:17PM (#25200523)
I think the key point in this case is that the performance characteristics of Deno don't significantly differ from TypeScript independently transpiled to JavaScript and run in Node because the compilation pipeline is more or less the same (Deno is using tsc and v8 internally)
Re:Tips for Performant TypeScript by ulucs on Tuesday November 24, 2020 @01:06PM (#25201098)
I think the distinction will hold when you can access type information at runtime
Re:Tips for Performant TypeScript by ragnese on Wednesday November 25, 2020 @03:01PM (#25213617)
Why? Haskell doesn't even have runtime type information. So what would you call the stuff that runs after I compile my Haskell code? Not-Haskell?