3 ms·
µTorrent is written in C++, and you could never, ever, make it so fast and small using any other language. Citation needed. I think it could be done easily in
by jrockway 17y ago
µTorrent is written in C++, and you could never, ever, make it so fast and small using any other language.
Citation needed. I think it could be done easily in Haskell, or Erlang, or Common Lisp, or even Java. (Actually, I bet it would even be fine in Perl/Python/Ruby.) A bittorrent client's speed comes from an efficient TCP stack and some minimal userspace use of non-blocking IO (or lightweight threads). It's basically glue between epoll (or similar), some disk reads and writes, and a tiny bit of algorithmic code.
It is unlikely that C++ is the best choice for this sort of application. It will work and it will be fast, but it will probably be just as fast in safer languages too.
- blasdel 17y agoYou're right that it could be easily done in any other language on a modern Unix, but µTorrent is written extremely closely for Win32 -- which is exactly why it's so terrific on that platform. The thing is brimming with features, insanely fast, and the self-contained executable is only 282kb! My favorite torrent client is rtorrent (written in C), which has a lightweight featureful ncurses interface, and its executable on one of my Linux x86 boxes is 680k + 586k for libtorrent! He's almost certainly right that you could never, ever, make it so fast and small using any other language ON WINDOWS.
- dtf 17y agortorrent is written in C++, as is the underlying libtorrent library. Check if those binaries are stripped though.
- kragen 17y agoThere are other languages you could make it small in, but those languages probably aren't among them. Haskell: Hugs 98 is 723K, but it depends on /usr/lib/hugs, which is 7.3M. GHC can almost do it; I compiled a "hello, world" program with GHC and it "only" came out to 366K, which is 84K bigger than μTorrent's reported size. With UPX, however, it packs to 130k. (ocamlopt's tax is in the same range.) Maybe Haskell would be an option? Or does it bloat up when you include the libraries you'd need for this? Erlang: My Erlang install is 97M. I don't know how much of that is minimally necessary to run things, but /usr/lib/erlang/erts-5.6.3 is 3.6M, 12 times the size of μTorrent. Stand Alone Erlang (http://www.sics.se/~joe/sae.html http://www.sics.se/~joe/sae.html) is 1.5MB compressed. Common Lisp: All the Common Lisp implementations are pretty big (SBCL, say, is 53M, of which 25M is the image sbcl.core), and they can't produce a standalone executable without including most of the environment. So you're starting at 25M. Java: The JRE on my system is 98 megabytes, so a Java application to run on Win32 will be 98 megabytes plus the application code. Even if you compile your app with GCJ, libgcj is 33 megabytes. Now, you could argue that the size of this stuff isn't relevant because it isn't specific to your hypothetical Common Lisp implementation of BitTorrent, but could also be used by whatever other Common Lisp programs the user has installed. But you would be treating a very-low-probability event as if it were normal. Languages — or rather, language implementations — that could make a 300k runnable BitTorrent client include not just C and C++, but also Forth, assembly, Pascal, Eiffel, and any number of other fatally flawed niche languages that don't require hundreds of kilobytes of libraries just to initialize a process and exit. There are probably also Scheme implementations that would work. Just about anything that has a reasonably small bytecode interpreter and lets you package the rest of your program as bytecode would probably win. x86 code is pretty grossly bloated by comparison to a good compact bytecode. (But compressible. See comment above about UPX.) The only other practical alternative I know of would be Lua, which only costs you about half of your space budget for the interpreter itself. Lua's "bytecode" is actually wordcode, but presumably UPX or something similar would squeeze it down to a reasonable size. It's my understanding that μTorrent does not need to ship with any shared libraries to run; the <300k of the executable alone is sufficient. You may think this is unimportant but I think that is an unconcern based in unusual wealth: you probably own your own computer to install software on persistently, probably several of them, you probably have several hundred kilobits per second of bandwidth to download software with, so you probably don't care how long it takes to download something or how much of a 256MB USB pendrive it takes up. It's certainly true that there are any number of languages you could write a BitTorrent client in that would be just as fast.
- jrockway 17y agoBut let's face it -- micro-optimizing the space of the image on disk is a completely useless optimization these days. You are also not including the shared libraries that the binary uses. When making my argument in the grandparent post, I did not even consider the size aspect to be worth discussing. If this is somehow important to you, then my argument does not apply.
- ilyak 17y agoWhy would you need a tiny bittorent image when the first it would download would cover the fattest image, ten to one? Come on, bittorent is for flacs and movies.
- sb 17y agoI am usually the last one to even read language flame wars, let alone participate in them, but how exactly are Eiffel, Forth and Pascal fatally flawed?
- ido 17y ago>Java: The JRE on my system is 98 megabytes, so a Java application to run on Win32 will be 98 megabytes plus the application code. Even if you compile your app with GCJ, libgcj is 33 megabytes. > Now, you could argue that the size of this stuff isn't relevant because it isn't specific to your hypothetical Common Lisp implementation of BitTorrent, but could also be used by whatever other Common Lisp programs the user has installed. But you would be treating a very-low-probability event as if it were normal. I am pretty sure the vast majority of users already have the JRE installed, and if they don't it's a download that's around 15mb.
- agazso 17y ago> I think it could be done easily in Haskell, or Erlang, or Common Lisp, or even Java. Real life example needed. I hear a lot about what could be done in those languages, but in the end, the programs that get the work done are written in C or C++.
- pavelludiq 17y agoThe first bit-torrent client was written in python: http://en.wikipedia.org/wiki/BitTorrent_(software) http://en.wikipedia.org/wiki/BitTorrent_(software)
- agazso 17y agoYeah, I am aware of that fact. I also expected someone would say Azureus (now called Vuze). But if you check out the peers in your torrent client, you will see that the majority of users use utorrent. Anyways it's not just about torrent client (which is not a too complicated piece of software) but other kinds of desktop and server applications, that are required to have low latency and small footprint. Rhetorical question: why all major browsers are written in C/C++? Don't get me wrong, I like dynamic languages, currently I am working in python (besides C++), but the main advantage for me in those languages are rapid prototyping/development and lots of built in libraries, not the performance.
- jrockway 17y agowhy all major browsers are written in C/C++? Because they are all very, very old codebases. Firefox's UI code is all JavaScript, BTW.
- blub 17y agoI would have been impressed if you had created the software in one of those languages and it was demonstrably as fast and small as the equivalent C or C++ software. Unfortunately your post looks more like "I can write a stackoverflow.com clone in a weekend".