Ask HN: Compiled Web App

5 points by alcover 6 years ago

I desperately want to build radically fast and lean web apps.

My stack at the moment is nginx > nodejs > sqlite. To step it up I want to replace nodejs with a compiled app. What language should I use ?

Precision : I'd prefer a C-like language since I'm comfortable in JS and C.

- C/C++ are excluded for obvious reasons.

- D looks REALLY nice but lacks momentum at first glance. (few packages - only one for async-http, one for sqlite - and a not-so-busy forum)

- Go ? I'd like to avoid it.

- Zig : as alluring as D but not stabilized.

- Rust : too unfamiliar.

simplecomplex 6 years ago

Haskell!

If you aren't proficient in a functional language like Haskell then you haven't completed your programming education. Go, Rust, D, etc. are all just C with fancy features. Change your whole programming paradigm.

Here's a great deep-dive into Haskell web server performance: https://www.aosabook.org/en/posa/warp.html

And if you're building an API you don't need to code! Just throw postgREST in front of a postgreSQL database and get a haskell-powered API for free. No need to write a web server.

  • alcover 6 years ago

    Damn.. that Warp lib looks powerful. Although from 2012, that benchmark against Nginx is unbelievable.

    > Go, Rust, D, etc. are all just C with fancy features

    Come on.. Their fanciness is very helpful. Doing web in C is tedious, insecure.

    > Change your whole programming paradigm.

    That is no small endeavour but I hear you !

explorigin 6 years ago

Need more info. What do you mean by radically fast? Unless you're doing lots of computation in your web request, then the "steering code" that is currently nodejs is almost never your bottleneck. 90% of the time your database is your bottleneck. sqlite can be crazy fast for one request at a time so it just depends on your app.

  • alcover 6 years ago

    By 'radically' I mean the fastest possible - short of writing a single blob in C integrating an http server.

    Since I want to keep it modular, the db part with sqlite is already optimal. Now I need the app on par : statically typed, compiled.

therockhead 6 years ago

I know you said Rust was too unfamiliar but if you want the efficiency of C++ but in a safe language this is where I would start (and what I’m currently learning). For what it’s worth, the Rust web framework Actix has some of the best performance numbers on techempower.

  • alcover 6 years ago

    Thank you. Indeed it ranks top. Followed by.. a Java framework (es4x) ?

    The D one (vibed) doesn't shine much. Alas.

    Maybe you're right and I should take the dive with Rust.

fouric 6 years ago

If you're willing to exclude D because it "lacks momentum", Go because you'd "like to avoid it", and Rust because it's "too unfamiliar", then you're really out of options. I don't think there exist any other performant, popular, compiled languages that are similar to Javascript; all of them fail one of your criteria or another:

- Haskell: very fast but probably more "unfamiliar" to you than Rust

- Common Lisp: fast, very stable, easier than Haskell (semantics similar to Python/Javascript) but definitely not mainstream

- FORTH: very fast but memory-unsafe and semantically+syntactically almost polar opposite of most popular languages

  • alcover 6 years ago

    Thank you,

    - I don't exclude D but it means some untrivial learning in spite of its semblance to C. I don't have infinite time to learn all promising C++ replacements.

    - Haskell.. really ? Plus it's not fast at all it seems.

    - Lisp : interesting idea. I'd prefer a C-like language but learning it expands your mind they say.

jimnotgym 6 years ago

C# and .net core sounds like a good solution to your rather vague problem. What are you trying to do?

  • alcover 6 years ago

    It's more of an inclination for speed than a problem. I have no problem with my current stack.

    C# and .NET are VM/bytecode I think and like 1/4th the speed of C.

    • jimnotgym 6 years ago

      Perhaps they are faster than well written C, which you say you have discounted, do doesn't bear comparison.

      There have been several articles on HN stating that .NET core is considerable less resource intensive than Node in real world use cases.

      I'm not clear you have a real world use case though.

    • jetti 6 years ago

      >C# and .NET are VM/bytecode I think and like 1/4th the speed of C.

      You never mention you want natively compiled languages but just compiled languages.

giaour 6 years ago

Why would you like to avoid Go? It's pretty ergonomic for programmers with C experience and can compile a web app plus its dependencies into a standalone binary.

  • alcover 6 years ago

    Honestly I may have no good reason except maybe speed.

    I just read that Go is not best for low-level optimizations, and memory size.

billconan 6 years ago

I'm using c++/mongodb for my backend.

I'm gonna rewrite my backend using epoll and coroutine.

  • alcover 6 years ago

    Exactly what I want to achieve. Compiled and evented.

    D permits that. I guess you are comfortable with C++ but I would not even try..