News for hackers. Stuff that matters.
Re:The computers are fast, but you don't know it by jcelerier on Thursday June 16, 2022 @03:57PM (#31770238)
> I agree 100%. I wish every software engineer would spent at least a little time writing some programs in bare C and running them to get a feel for how fast a native executable can start up and run. It is breathtaking if you're used to running scripting languages and VMs.

Conversely when 99.9% of the software you use in your daily life is blazing fast C / C++, having to do anything in other stacks is a complete exercise in frustration, it feels like going back a few decades in time

Re:The computers are fast, but you don't know it by p1esk on Thursday June 16, 2022 @04:00PM (#31770269)
Conversely when 99.9% of the software you use in your daily life is user friendly Python, having to do anything in C/C++ is a complete exercise in frustration, it feels like going back a few decades in time
Re:The computers are fast, but you don't know it by bayindirh on Thursday June 16, 2022 @04:17PM (#31770456)
As a person who uses both languages for various needs, I disagree. Things which takes minutes in optimized C++ will probably take days in Python, even if I use the "accelerated" libraries for matrix operations and other math I implement in C++.

Lastly, people think C++ is not user friendly. No, it certainly is. It needs being careful, yes, but a lot of things can be done in less lines then people expect.

Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @04:43PM (#31770748)
I was a C++ dev in a past life and I have no particular fondness for Python (having used it for a couple of decades), and "friendliness" is a lot more than code golf. It's also "being able to understand all of the features you encounter and their interactions" as well as "sane, standard build tooling" and "good debugability" and many other things that C++ lacks (unless something has changed recently).
Re:The computers are fast, but you don't know it by jb_s on Friday June 17, 2022 @01:12AM (#31774350)
I delved into Python recently to work on some data science hobbies and a Chess program and it's frankly been fairly shit compared with other languages I use.

Typescript (by way of comparison with other non-low-level languages) just feels far more solid wrt type system, type safety, tooling etc. C# (which I've used for years) is faster by orders of magnitude and IMO safer/easier to maintain.

Re:The computers are fast, but you don't know it by rocqua on Friday June 17, 2022 @04:28AM (#31775532)
I have found that Python with `mypy --strict` for type-checking is actually quite nicely typed.
Re:The computers are fast, but you don't know it by gpderetta on Friday June 17, 2022 @05:57AM (#31776073)
Python is a powerful yet beginner friendly language with a very gentle learning slope, but I would still take C++ tooling and debuggability any day over Python.
Re:The computers are fast, but you don't know it by throwaway894345 on Friday June 17, 2022 @10:18AM (#31778570)
Nah man, I've spent way too much time trying to piece together libraries to turn core dumps into a useful stack trace. Similarly, as miserable as Python package management is, at least it has a package manager that works with virtually every project in the ecosystem. I actually really like writing C++, but there are certain obstacles that slow a developer down tremendously--I could forgive them if they were interesting obstacles (e.g., I can at least amuse myself pacifying Rust's borrow checker), but there's no joy in trying to cobble together a build system with CMake/etc or try to get debug information for a segfault.
Re:The computers are fast, but you don't know it by gpderetta on Friday June 17, 2022 @10:39AM (#31778893)
I won't spend any positive words on cmake (I'm a plain make fan), but...

> or try to get debug information for a segfault

what's the problem with opening the core dump with gdb and looking at the backtrace?

Re:The computers are fast, but you don't know it by throwaway894345 on Friday June 17, 2022 @02:41PM (#31782516)
You need to provide all of the libraries referenced by the core dump (at the specific versions and compiled with debug symbols) to get gdb to produce a useful backtrace. It's been a decade since I've done professional C++ development, so I'm a bit foggy on the particulars.
Re:The computers are fast, but you don't know it by jcelerier on Friday June 17, 2022 @04:06PM (#31783558)
we're in 2022, gdb asks me "can i download missing symbols from the internet" when it loads a binary and does it
Re:The computers are fast, but you don't know it by throwaway894345 on Friday June 17, 2022 @09:26PM (#31786516)
Glad to hear the 2022 C++ ecosystem is finally catching up on some regards, but how does it know which version of those dependencies to download, and how does it download closed source symbols?
Re:The computers are fast, but you don't know it by jcelerier on Saturday June 18, 2022 @03:35AM (#31787950)
I mean, if it's closed source you're not getting the debug symbols in any case lol, no matter which language.

It uses debuginfod for fetching symbols - here it "just works".

Re:The computers are fast, but you don't know it by TremendousJudge on Friday June 17, 2022 @06:35AM (#31776277)
>unless something has changed recently

No, it's even worse -- there are even MORE ways of doing the same thing now.

Re:The computers are fast, but you don't know it by bb88 on Thursday June 16, 2022 @04:36PM (#31770681)
Java and Go were both responses to how terrible C++ actually is. While there are footguns in python, java, and go, there are exponentially more in C++.
Re:The computers are fast, but you don't know it by bayindirh on Thursday June 16, 2022 @04:41PM (#31770730)
As a person who wrote Java and loved it (and I still love it), I understand where you're coming from, however all programming languages thrive in certain circumstances.

I'm no hater of any programming language, but a strong proponent of using the right one for the job at hand. I write a lot of Python these days, because I neither need the speed, nor have the time to write a small utility which will help a user with C++. Similarly, I'd rather use Java if I'm going to talk with bigger DBs, do CRUD, or develop bigger software which is going to be used in an enterprise or similar setting.

However, if I'm writing high performance software, I'll reach for C++ for the sheer speed and flexibility, despite all the possible foot guns and other not-so-enjoyable parts, because I can verify the absence of most foot-guns, and more importantly, it gets the job done the way it should be done.

Re:The computers are fast, but you don't know it by bb88 on Thursday June 16, 2022 @04:55PM (#31770862)
I've seen a lot of bad C++ in my life, and have seen Java people write C++ like they would Java.

Writing good C++ is hard. People who think they can write good C++ are surprised to learn about certain footguns (static initialization before main, exception handling during destructors, etc).

I found this reference which I thought was a pretty good take on the C++ learning curve.

https://www.reddit.com/r/ProgrammerHumor/comments/7iokz5/c_l...

Re:The computers are fast, but you don't know it by bayindirh on Thursday June 16, 2022 @05:02PM (#31770943)
> I've seen a lot of bad C++ in my life, and have seen Java people write C++ like they would Java.

Ah, don't remind me Java people write C++ like they write Java, I've seen my fair share, thank you.

> Writing good C++ is hard.

I concur, however writing good Java is also hard. e.g. Swing has a fixed and correct initialization/build sequence, and Java self-corrects if you diverge, but you get a noticeable performance hit. Most developers miss the signs and don't fix these innocent looking mistakes.

I've learnt C++ first and Java later. I also tend to hit myself pretty hard during testing (incl. Valgrind memory sanity and Cachegrind hotpath checks), so I don't claim I write impeccable C++. Instead I assume I'm worse than average and try to find what's wrong vigorously and fix them ruthlessly.

Re:The computers are fast, but you don't know it by pjmlp on Friday June 17, 2022 @04:55AM (#31775697)
> Ah, don't remind me Java people write C++ like they write Java, I've seen my fair share, thank you.

I always find this remark amusing, given that Java adopted the common patterns in C++ toolkits that precedded Java.

If anything they are writting C++ like it used to be on Turbo Vision, Object Windows Library, MPW, PowerPlant, MFC, wxWindows,....

Re:The computers are fast, but you don't know it by bayindirh on Friday June 17, 2022 @05:18AM (#31775840)
The remark is rooted from variable naming and code organization mostly. I've seen a C++ codebase transferred to a java developer, and he disregarded everything from the old codebase. Didn't refactor the old code, and the new additions were done Java Style. CamelCase file/variable/function names, every class on its own file with ClassName.cpp files littered everywhere, it was a mess.

The code was math-heavy, and became completely unreadable and un-followable. He remarked "I'm a java developer, I do what I do, and as long as it works, I don't care".

That was really bad. It was a serious piece of code, in production.

Re:The computers are fast, but you don't know it by pjmlp on Friday June 17, 2022 @06:20AM (#31776196)
So basically " like it used to be on Turbo Vision, Object Windows Library, MPW, PowerPlant, MFC, wxWindows,..."
Re:The computers are fast, but you don't know it by rot13xor on Thursday June 16, 2022 @06:28PM (#31771777)
The biggest weakness of C++ (and C) is non-localized behavior of bugs due to undefined behavior. Once you have undefined behavior, you can no longer reason about your program in a logically consistent way. A language like Python or Java has no undefined behavior so for example if you have an integer overflow, you can debug knowing that only data touched by that integer overflow is affected by the bug whereas in C++ your entire program is now potentially meaningless.
Re:The computers are fast, but you don't know it by kllrnohj on Thursday June 16, 2022 @07:31PM (#31772269)
That is a radically gross misunderstanding of what undefined behavior is and how it can (and mostly how it cannot) propagate.
Re:The computers are fast, but you don't know it by Too on Saturday June 18, 2022 @01:19AM (#31787420)
Memory write errors (some times induced by UB) in one place of the program can easily propagate and later fail in a very different location of the program, with absolutely zero diagnostics of why your variable suddenly had a value out of possible range.

This is why valgrind, asan and friends exist. They move the error diagnostic to the place where error actually happened.

Re:The computers are fast, but you don't know it by loup-vaillant on Friday June 17, 2022 @04:31AM (#31775546)
Actually it's not, Chandler Carruth notwithstanding.

If your C++ program exhibit undefined behaviour, the compiler is allowed to format your entire hard drive. Or encrypt it and display a "plz pay BTC" message. That's called a vulnerability. Real and meaningful security checks have been removed as "dead code" because of signed integer overflow (which is undefined behaviour by default).

If anything, I would guess the gross misunderstanding sprouted somewhere between the specs and the compiler writers. Originally, UB was mostly about bailing out when the underlying platform couldn't handle this particular case, or explicitly ignoring edge cases to simplify implementations. Now however it's also a performance thing, and if anything is marked as UB then it's fair game for the optimiser — even if it could easily be well defined, like signed integer overflow on 2's complement platforms.

Re:The computers are fast, but you don't know it by kllrnohj on Friday June 17, 2022 @06:28AM (#31776241)
> If your C++ program exhibit undefined behaviour, the compiler is allowed to format your entire hard drive. Or encrypt it and display a "plz pay BTC" message.

No, it isn't. That's a completely made up fabrication. And if you had a compiler that was going to do that, then what the standard says or if there's undefined behavior is obviously not relevant or significant in the slightest.

The majority of the UB optimization complaints are because the compiler couldn't tell that UB was happening. It didn't detect UB and then make an evil laugh and go insane. That's not how this works.

Compilers cannot detect UB and then do things in response within the rules of the standard. Rather, they are allowed to assume UB doesn't happen. That's it, that's all they do. They just behave as though your source has no UB at all. As far as the compiler is concerned, UB doesn't exist and can't happen.

When a compiler can detect that UB is happening it'll issue a warning. It never silently exploits it.

> Real and meaningful security checks have been removed as "dead code" because of signed integer overflow (which is undefined behaviour by default).

Real and meaningful security checks have been removed because the security check happened after the values were already used in specific ways, not because of UB. The values were already specified in the source code to be a particular thing via earlier usage. UB is just the shield for developers who wrote a bug to hide behind to avoid admitting they had a bug.

Use UBSAN next time.

> even if it could easily be well defined, like signed integer overflow on 2's complement platforms.

Signed integer overflow is defined behavior, that's not UB. Also platform specific behavior is something the standard doesn't define - that's why it was UB in the first place.

It is kinda ridiculous it took until C++20 for this change, though

Re:The computers are fast, but you don't know it by loup-vaillant on Friday June 17, 2022 @09:55AM (#31778201)
> > UB allows the to format/encrypt your entire hard drive.

> No, it isn't. That's a completely made up fabrication.

Ever heard of viruses exploiting buffer overflows to make arbitrary code execution? One cause of that can be a clever optimisation that noticed that the only way the check fails is when some UB is happening. Since UB "never happens", the check is dead code and can be removed. And if the compiler noticed after it got past error reporting, you may not even get a warning.

You still get the vulnerability, though.

> UB is just the shield for developers who wrote a bug to hide behind to avoid admitting they had a bug.

C is what it is, and we live with it. Still, it would be unreasonable to say that the amount of UB it harbours isn't absolutely ludicrous. It's like asking children to cross a poorly mapped minefield and blame them when they don't notice a subtle cue and blow themselves up.

Also, UBSan is not enough. I ran some of my code unde ASan, MSan, and UBSan, and the TIS interpreter still found a couple things. And I'm talking about pathologically straight-line code where once you test for all input sizes you have 100% code path coverage.

> Signed integer overflow is defined behavior, that's not UB.

The C99 standard explicitly states that left shift is undefined on negative integers, as well as signed integers when the result overflows. I had to get around that one personally by replacing x<<n by x(1<<n) on carry propagation code.

Strangely enough I cannot find explicit mentions of signed integer overflow for regular arithmetic operators, but apparently the C++ standard has an explicit mention: https://stackoverflow.com/questions/16188263/is-signed-integ...

> Also platform specific behavior is something the standard doesn't define - that's why it was UB in the first place.*

One point I was making is, compiler writers didn't get that memo. They treat any UB as fair game for their optimisers. It doesn't matter that signed integer overflow was UB because of portability, it still "never happens".

Re:The computers are fast, but you don't know it by kllrnohj on Friday June 17, 2022 @10:28AM (#31778734)
> C is what it is, and we live with it. Still, it would be unreasonable to say that the amount of UB it harbours isn't absolutely ludicrous.

There's a lot of ludicrous stuff about C and I wouldn't recommend anyone use it for anything. Not when Rust and C++ exist.

But UB really isn't the scary boogie man. There could probably stand to be a `as-is {}` block extension for security checks, but that's really about it.

Re:The computers are fast, but you don't know it by loup-vaillant on Friday June 17, 2022 @10:46AM (#31778978)
I'm sorry, C++?!?

Granted, C is underpowered and I would like namespaces and generics. But from a safety standpoint nowadays, C++ is just as bad. Not only is is monstrously complex, it still has all the pitfalls of C. C++ may have been "more strongly typed" back in the day, but now compiler warnings made up for that small difference.

Granted, C++ can be noticeably safer if you go RAII pointer fest, but then you're essentially programming in Java with better code generation and a worse garbage collector.

---

There's also a reason to still write C today: its ubiquity. Makes it easier to deploy everywhere and to talk to other languages. It's mostly a library thing though, and the price in testing effort and bugs is steep.

Re:The computers are fast, but you don't know it by kllrnohj on Friday June 17, 2022 @07:00PM (#31785548)
> I'm sorry, C++?!?

C++ had a defined multithreaded memory model and 2's compliment behavior before C did. Since you're all about UB, that kinda matters. A lot.

Re:The computers are fast, but you don't know it by loup-vaillant on Friday June 17, 2022 @08:06PM (#31786072)
Well, I'll check who gets rid of all undefined overflows first. 2's complement is nice and dandy, but if overflow is still undefined that doesn't buy me much.

Point taken about multi threading.

Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @04:45PM (#31770767)
I've written a whole bunch of all of those languages, and they each occupy a different order of magnitude of footguns. From fewest to most: Go (1X), Java (10X), Python (100X), and C++ (1000X).
Re:The computers are fast, but you don't know it by kaba0 on Thursday June 16, 2022 @06:49PM (#31771976)
Go has much more footguns in my opinion. Just look at the recent thread on the topic: https://news.ycombinator.com/item?id=31734110
Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @10:04PM (#31773324)
Most of those aren’t “footguns” at all, but rather preferences (naming conventions, nominal vs structural subtyping) and many others are shared with Python (“magical behavior”, Go’s structural subtyping is strictly better for finding implementations than Python’s duck typing) or non-issues altogether (“the Go compiler won’t accept my invalid Go code”).

The “forget to check an error” one is valid, but rare (usually a function will return data and an error, and you can’t touch the data without handling the error)—moreover, once you use Go for a bit, you sort of expect errors by default (most things error). But yeah, a compilation failure would be better. Personally, the things that really chafe me are remembering to initialize maps, which is a rarer problem in Python because there’s no distinction between allocation and instantiating (at least not in practice). I do wish Go would ditch zero types and adopt sum types (use Option[T] where you need a nil-like type), but that ship has sailed.

I’ve operated services in both languages, and Python services would have tons of errors that Go wouldn’t have, including typos in identifiers, missing “await”s, “NoneType has no attribute ‘foo’”, etc but also considerably more serious issues like an async function accidentally making a sync call under the covers, blocking the event loop, causing health checks to fail, and ultimately bringing down the entire service (same deal with CPU intensive endpoints).

In Go, we would see the occasional nil pointer error, but again, Python has those too.

Re:The computers are fast, but you don't know it by astrange on Thursday June 16, 2022 @11:42PM (#31773882)
Java is largely based on Objective-C, not on C++. It's a bit hard to tell because they removed messaging though.

It is memory safe but otherwise I think it was an imitation, not a reaction, to ObjC features.

Re:The computers are fast, but you don't know it by LoveMortuus on Thursday June 16, 2022 @04:52PM (#31770833)
I personally find C++ more friendly, just because of the formatting that python forces upon you.

But I do have to say that I never managed to really get into python, it always just felt like to much of a hassle, thus I always avoided it if possible.

Re:The computers are fast, but you don't know it by chowells on Friday June 17, 2022 @02:18AM (#31774667)
The formatting python enforces is just "layout reflects control flow". It's really not any more difficult than that, and it's a lot better than allowing layout to lie about control flow.

https://www.synopsys.com/blogs/software-security/understandi...

Re:The computers are fast, but you don't know it by doctor_eval on Friday June 17, 2022 @08:31AM (#31777123)
To each their own, but Python's use of indenting for structure is why I never tried it. It just felt, to me, like it was solving one problem with another.

I think Go gets this right: it consistently uses braces for structure, but has an idiomatic reformatting tool that is applied automatically by most IDEs. This ensures that the format and indentation always perfectly matches the code structure, without needing to use invisible characters.

Re:The computers are fast, but you don't know it by idlehand on Thursday June 16, 2022 @05:12PM (#31771029)
I didn't like it for years but then I kind of got into it for testing out machine learning and I found it kind of neat. My biggest gripe is no longer the syntax but the slowness, trying to do anything with even a soft performance requirement means having to figure out how to use a library that calls C to do it for you. Working with large amounts of data in native Python is noticeably slower than even NodeJS.
Re:The computers are fast, but you don't know it by l33t2328 on Friday June 17, 2022 @02:49AM (#31774872)
> Things which takes minutes in optimized C++ will probably take days in Python, even if I use the "accelerated" libraries for matrix operations and other math

I’m gonna need an example because I do not believe this whatsoever.

Re:The computers are fast, but you don't know it by bayindirh on Friday June 17, 2022 @02:56AM (#31774925)
I'd rather open the code and show what I'm talking about, however I can not.

Let's say I'm making a lot of numerical calculations which are fed from a lockless queue with atomic operations to any number of cores you want, where your performance is limited by the CPU cores' FPU performance and the memory bandwidth (in terms of both transfer speed and queries that bus can handle per second).

As I noted below, that code can complete 1.7 million complete evaluations per core, per second on older (2014 level) hardware, until your memory controller congests with all the requests. I need to run benchmarks on a newer set of hardware to get new numbers, however I seriously lack the time today to do so and provide you new numbers.

Re:The computers are fast, but you don't know it by necovek on Friday June 17, 2022 @06:45AM (#31776346)
There are definitely operations you cannot speed up in Python as much as in other languages, unless you implement it in one of those other languages and interface it in Python.

That much is obvious from Python providing a bunch of C-based primitives in stdlib (otherwise they'd just be written in pure Python).

In many cases, you can make use of the existing primitives to get huge improvements even with pure Python, but you are not beating optimized C++ code (which almost has direct access to CPU vector operations as well).

Python's advantage is in speed of development, not in speed of execution. And I say that as a firm believer that majority of the Python code in existence today could be much faster only if written with the understanding of Python's internal structures.

Re:The computers are fast, but you don't know it by p1esk on Thursday June 16, 2022 @04:27PM (#31770580)
Which “accelerated” libraries for matrix operations are you talking about?

Try writing a matmul operation in C++ and profile it against the same thing done in Numpy/Pytorch/TensorFlow/Jax. You’ll be surprised.

Re:The computers are fast, but you don't know it by gpm on Thursday June 16, 2022 @04:39PM (#31770701)
This is because numpy and friends are really good at matmul's.

As soon as you step out of the happy path and need to do any calculation that isn't at least n^2 work for every single python call you are looking at order of magnitude speed differences.

Years ago now (so I'm a bit fuzzy on the details) a friend asked me to help optimize some python code that took a few days to do one job. I got something like a 10x speedup using numpy, I got a further 100x speedup (on the entire program) by porting one small function from optimized numpy to completely naive rust (I'm sure c or c++ would have been similar). The bottleneck was something like generating a bunch of random numbers, where the distribution for each one depended on the previous numbers - which you just couldn't represent nicely in numpy.

What took 2 days now took 2 minutes, eyeballing the profiles I remember thinking you could almost certainly get down to 20 seconds by porting the rest to rust.

Re:The computers are fast, but you don't know it by rubyskills on Thursday June 16, 2022 @05:41PM (#31771336)
Have you tried porting the problem into postgres? Not all big data problems can be solved this way but I was surprised what a postgres database could do with 40 million rows of data.
Re:The computers are fast, but you don't know it by gpm on Thursday June 16, 2022 @06:03PM (#31771571)
I didn't, I don't think using a db really makes sense for this problem. The program was simulating a physical process to get two streams of timestamps from simulated single-photon detectors, and then running a somewhat-expensive analysis on the data (primarily a cross correlation).

There's nothing here for a DB to really help with, the data access patterns are both trivial and optimal. IIRC it was also more like a billion rows so I'd have some scaling questions (a big enough instance could certainly handle it, but the hardware actually being used was a cheap laptop).

Even if there was though - I would have been very hesitant to do so. The not-a-fulltime-programmer PhD student whose project this was really needed to be able to understand and modify the code. I was pretty hesitant to even introduce a second programming language.

Re:The computers are fast, but you don't know it by necovek on Friday June 17, 2022 @06:35AM (#31776278)
That's definitely quite curious: I am sure pure Python could have been heavily optimized to reach 2 minutes as well, though. Random number generation in Python is C-based, so while the pseudo-random generators from Python's random module might be slow, it's not because of Python itself (https://docs.python.org/3/library/random.html is a different implementation from https://man7.org/linux/man-pages/man3/random.3.html).

Call overhead and loop overhead is pretty big in Python though. The way to work around that in Python is to use C-based "primitives", like the stuff from itertools and all the builtins for set/list/hash processing (thus avoiding the n^2 case in pure Python). And when memory is an issue (preallocating large data structures can be slow as well), iterators! (Eg. compare use of range() in newer Python with use of list(range())).

Re:The computers are fast, but you don't know it by gpm on Friday June 17, 2022 @02:33PM (#31782416)
I'm reasonably sure the PRNG being used in the python version came from numpy and was implemented in C (or other native code, not python). The problem was that the necessary control flow and varying parameters around it meant you had to call it once per value from python (and you had to generate a lot of values).

And if I recall correctly there was no allocation in the hot loop, with a single large array being initialized via numpy to store the values before hand. Certainly that's one of the first things I would think to fix.

I was strongly convinced at the time that there was no significant improvement left in python. With >99% of the time being spent in this one function, and no way to move the loop into native code given the primitives available from numpy. Admittedly I could have been wrong, and I'm not about to revisit the code now, since it has been years and it is no longer in use - so everything I'm saying is based off of years old memories.

Re:The computers are fast, but you don't know it by necovek on Saturday June 18, 2022 @09:10AM (#31789515)
Sure, numpy introduces its own set of restrictions. I was mostly referring to taking a different approach before turning to numpy, but it could very well be true.

In essence, doing what you did is the way to get performance out of Python when nothing else works.

Re:The computers are fast, but you don't know it by dragonwriter on Friday June 17, 2022 @02:45PM (#31782571)
> The problem was that the necessary control flow and varying parameters around it meant you had to call it once per value from python (and you had to generate a lot of values).

Sounds like a Numba use case.

Re:The computers are fast, but you don't know it by gpm on Friday June 17, 2022 @02:51PM (#31782654)
Huh, I didn't know that was a thing. At a super high level glance I suspect yes.
Re:The computers are fast, but you don't know it by bayindirh on Thursday June 16, 2022 @04:35PM (#31770676)
The code I've written and still working on is using Eigen, which TensorFlow also uses for its matrix operations, so, I'm not far off from these guys in terms of speed, if not ahead.

The code I've written can complete 1.7 million evaluations per core, per second, on older hardware, which is used to evaluate things up to 1e-6 accuracy, which pretty neat for what I'm working on.

[0]: https://eigen.tuxfamily.org/index.php?title=Main_Page

Re:The computers are fast, but you don't know it by easytiger on Friday June 17, 2022 @01:17AM (#31774364)
Doesn't numpy use a natively compiled Fortran or c library for that?

https://github.com/numpy/numpy/blob/main/numpy/core/src/mult...

Re:The computers are fast, but you don't know it by p1esk on Friday June 17, 2022 @02:22AM (#31774702)
Why should I care what Numpy is written in? All I see is Python.
Re:The computers are fast, but you don't know it by easytiger on Friday June 17, 2022 @03:26AM (#31775133)
Because it is like saying you use a bash script to configure and launch a c++ application and saying it is a bash script. Python is not a high performance language, it isn't meant to be and it's strengths lie elsewhere. One of it's great strengths is interop with c libs.

Your assertion was that numpy etc will be faster than something else despite being python:

> Try writing a matmul operation in C++ and profile it against the same thing done in Numpy/Pytorch/TensorFlow/Jax. You’ll be surprised.

I mean TensorFlow is c++/cuda!

Re:The computers are fast, but you don't know it by p1esk on Friday June 17, 2022 @04:12AM (#31775433)
I mean TensorFlow is c++/cuda!

No. When I write Tensorflow code I write Python. I don’t care what TF does under the hood just like I don’t care that Python itself might be implemented in C. Though I got to say TF is quite ugly and not a good example of Python’s user friendliness. But that’s another topic.

Re:The computers are fast, but you don't know it by gpderetta on Friday June 17, 2022 @06:00AM (#31776093)
But as soon as you step out of the optimized path, the performance cliff is huge. Also you are forced to work in non idiomatic awkward meta-languages.
Re:The computers are fast, but you don't know it by easytiger on Friday June 17, 2022 @05:35AM (#31775958)
As long as you know python is doing little to no computational work.
Re:The computers are fast, but you don't know it by necovek on Friday June 17, 2022 @06:40AM (#31776314)
That's a known and widely publicised trait of Python.

In the early days, Python tutorial warned against adding to strings by doing "+" even though it works because that performed a new allocation and string copy.

What you were asked to do was use fast, optimized C-based primitives like "\n".join(list_of_strings) etc.

Basically, Python is an "ergonomic" language built in C. Saying how something is implemented in C at the lower level is pointless, because all of Python is.

Yes, doing loops over large data sets in Python is slow. Which is why it provides itertools (again, C-based functions) in stdlib.

Re:The computers are fast, but you don't know it by gilbetron on Thursday June 16, 2022 @08:48PM (#31772797)
Aren't the fast parts of numpy written in C?
Re:The computers are fast, but you don't know it by gpm on Thursday June 16, 2022 @09:06PM (#31772918)
And fortran. Which really doesn't matter that much as long as that doesn't leak to the users of numpy, and it doesn't really. The only issue is that it means if you're doing something that doesn't fit the APIs exposed by the native code (in a way where the hot loops are in native code) it's roughly as slow as normal python.
Re:The computers are fast, but you don't know it by gilbetron on Friday June 17, 2022 @08:18AM (#31777010)
But it does for the argument of a language being fast, which is what we are talking about here. I don't think it is an appropriate argument to say "Python is fast, look at numpy", when the core pieces are written in C/Fortran. It is disingenuous, at least to me.
Re:The computers are fast, but you don't know it by Shorel on Friday June 17, 2022 @02:43PM (#31782538)
The canonical answer would be uBLAS.

https://www.boost.org/doc/libs/1_75_0/libs/numeric/ublas/doc...

I think BLAS (a C version, not the boost one) is also the library numpy is using, as numpy is not written in python. That's why it is fast, it is C.

Re:The computers are fast, but you don't know it by tcfhgj on Friday June 17, 2022 @01:17PM (#31781296)
C++ isn't remotely user friendly.

Have you ever tried Rust? Compared to C++, it's like heaven

Re:The computers are fast, but you don't know it by tcfhgj on Thursday June 16, 2022 @07:18PM (#31772191)
C++ isn't user friendly.

Have you ever tried Rust? Compared to C++, it's like lawyer speech vs poetry

Re:The computers are fast, but you don't know it by kaba0 on Thursday June 16, 2022 @06:45PM (#31771932)
I call bullshit on that. You either don’t compare the same thing, but C++ is not that much faster than even Python.
Re:The computers are fast, but you don't know it by easytiger on Friday June 17, 2022 @01:19AM (#31774373)
That's simply not even remotely true, as someone who has written a lot of both
Re:The computers are fast, but you don't know it by mbrodersen on Friday June 17, 2022 @09:53PM (#31786662)
You clearly have strong opinions about things you don’t understand or have any experience with.
Re:The computers are fast, but you don't know it by pjvsvsrtrxc on Thursday June 16, 2022 @04:19PM (#31770489)
Yes, writing software in C/C++ is harder. It's a darn good thing most software is used much more frequently than it is written, isn't it?
Re:The computers are fast, but you don't know it by bena on Thursday June 16, 2022 @04:14PM (#31770427)
I kind of feel both statements.

I like writing things in python. It honestly feels like cheating at times. Being able to reduce things down to a list comprehension feels like wizardry.

I like having things written in C/C++. Because like every deep magic, there's a cost associated with it.

Re:The computers are fast, but you don't know it by tester756 on Thursday June 16, 2022 @04:08PM (#31770353)
Is performance inversely proportional to dev experience?

because what you wrote could be said about using C++ in the context of dev experience

10 compilers, IDEs, debuggers, package managers

and at the end of the day LLVM compiles 30min and uses tens of GBs of RAM on average hardware

I don't believe that this is the best we can get.

Re:The computers are fast, but you don't know it by jcelerier on Thursday June 16, 2022 @04:29PM (#31770607)
> and at the end of the day LLVM compiles 30min and uses tens of GBs of RAM on average hardware

I mean, that's the initial build.

Here's my compile-edit-run cycle in https://ossia.io which is nearing 400kloc, with a free example of performance profiling, I haven't found anything like this whenever I had to profile python. It's not LLVM-sized of course, but it's not a small project either, maybe in the medium-low C++ project size: https://streamable.com/o8p22f ; pretty much a couple seconds at most from keystroke to result, for a complete DAW which links against Qt, FFMPEG, LLVM, Boost and a few others. Notice also how my IDE kindly informs me of memory leaks and other funsies.

    C/C++ Header                      2212          29523          17227         200382
    C++                               1381          34060          13503         199259
Here's some additional tooling I'm developing - build times can be made as low as a few dozen milliseconds when one puts some work into making the correct API and using the tools correctly: https://www.youtube.com/watch?v=fMQvsqTDm3k
Re:The computers are fast, but you don't know it by pjvsvsrtrxc on Thursday June 16, 2022 @04:21PM (#31770510)
Huh?

"10 compilers, IDEs, debuggers, package managers" what are you talking about? (Virtually) No one uses ten different tools to build one application. I don't even know of any C++-specific package managers, although I do know of language-specific package managers for... oh, right, most scripting languages. And an IDE includes a compiler and a debugger, that's what makes it an IDE instead of a text editor.

"and at the end of the day LLVM compiles 30min and uses tens of GBs of RAM on average hardware" sure, if you're compiling something enormous and bloated... I'm not sure why you think that's an argument against debloating?

Re:The computers are fast, but you don't know it by tester756 on Thursday June 16, 2022 @05:11PM (#31771018)
>No one uses ten different tools to build one application.

I meant you have a lot of choices to make

Instead of having one strong standard which everyone uses, you have X of them which makes changing projects/companies harder, but for solid reason? I don't know.

>"and at the end of the day LLVM compiles 30min and uses tens of GBs of RAM on average hardware" sure, if you're compiling something enormous and bloated... I'm not sure why you think that's an argument against debloating?

I know that lines in repo aren't great way to compare those things, but

.NET Compiler Infrastructure:

20 587 028 lines of code in 17 440 files

LLVM:

45 673 398 lines of code in 116 784 files

The first one I built (restore+build) in 6mins and it used around 6-7GB of RAM

The second I'm not even trying because the last time I tried doing it on Windows it BSODed after using _whole_ ram (16GBs)

Re:The computers are fast, but you don't know it by archi42 on Friday June 17, 2022 @05:34AM (#31775949)
Compiling a large number of files on Windows is slow, no matter what language/compiler you use. It seems to be a problem with the program invocation, which takes "forever" on Windows. It's still fast for a human, but it's slow for a computer. Quite apt this comes up here ;-)

Source for claim: That's a problem we actually faced in the Windows CI at my old job. Our test suite invoked about 100k to 150k programs (our program plus a few 3rd party verification programs). In the Linux CI the whole thing ran reasonably fast, but the Windows CI took double as long. I don't recall the exact numbers, but if Windows incurs a 50ms overhead per program call you're looking at 1:20 (one hour twenty minutes) more runtime at 100k invocations.

Also I'm pretty sure I've built LLVM on 16GB memory. Took less than 10 minutes on a i7-2600. The number of files is a trade off: You can combine a bunch of small files into a large file to reduce the build time. You can even write a tool that does that automatically on every compile (and keeps sane debug info). But now incremental builds take longer, because even if you change only one small file, the combined file needs to be rebuild. That's a problem for virtually all compiled languages.

Re:The computers are fast, but you don't know it by tester756 on Friday June 17, 2022 @06:52AM (#31776393)
It's crazy that they have multiplied files count by 7 meanwhile the code just by 2

is it some C++ header file overhead? or they do something specific?

Re:The computers are fast, but you don't know it by archi42 on Monday June 20, 2022 @06:14AM (#31808473)
I can only guess, I am neither a LLVM nor a MSVC dev.

1. Compile times: If you have one file with 7000 LOC that and change one function in that file, the rebuild is slower than if you had 7 files with 1000 LOC instead.

2. Maintainability: Instead of putting a lot of code into one file, you put the code in multiple files for better maintainability. IIRC LLVM was FOSS from the beginning, so making it easy for lots of people to make many small contributions is important. I guess .NET was conceived as being internal to MS, so less people overall, but newcomers probably were assigned to a team for onboarding and then contributing to the project as part of that team. With other words: At MS you can call up the person or team responsible for that 10000 LOC monstrosity; but if all you got is a bunch of names with e-mail addresses pulled from the commit log, you might be in for a bad time.

3. Generated code: I don't know if either commit generated code into the repository. That can skew these numbers as well.

4. Header files can be a wild card, as it depends on how their written. Some people/projects just put the signatures in there and not too much details, others put the whole essays as docs for each {class, method, function, global} in there, making them huge.

For the record, by your stats .NET has 1180 LOC per file and LLVM 391 on average. That doesn't say a lot, the median would probably be better, or even a percentile graph. Broken down by type (header/definition vs. implementation). You might find that the distribution is similar and a few large outliers skew it (especially generated code). Or when looking at more, big projects you might find that these two are outliers. I can't say anything definite, and from an engineering perspective I think neither is "suspicious" or even bad.

My gut feeling says 700 would be a number I'd expect for a large project.

Re:The computers are fast, but you don't know it by jcelerier on Wednesday June 22, 2022 @04:20AM (#31833330)
> My gut feeling says 700 would be a number I'd expect for a large project.

aha, I remember when I was in class, the absolute rule our teachers gave us was no more than 200 lines per file

Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @04:47PM (#31770787)
I assume the parent was talking about the fragmentation in the ecosystem (fair point, especially regarding package management landscape and build tooling), but it's unclear.
Re:The computers are fast, but you don't know it by optimalsolver on Thursday June 16, 2022 @05:52PM (#31771444)
>I don't even know of any C++-specific package managers

https://conan.io/

Re:The computers are fast, but you don't know it by bhauer on Thursday June 16, 2022 @04:18PM (#31770479)
> Is performance inversely proportional to dev experience?

No. I feel there is great developer experience in many high performance languages: Java, C#, Rust, Go, etc.

In fact, for my personal tastes, I find these languages more ergonomic than many popular dynamic languages. Though I will admit that one thing that I find ergonomic is a language that lifts the performance headroom above my head so that I'm not constantly bumping my head on the ceiling.

Re:The computers are fast, but you don't know it by kaba0 on Thursday June 16, 2022 @06:51PM (#31771985)
You haven’t touched a C++ toolchain in the last decade, have you?
Re:The computers are fast, but you don't know it by spc476 on Thursday June 16, 2022 @05:31PM (#31771228)
TCC is a fast compiler. So fast, that at one time, one could use it to boot Linux from source code! But there's a downside: the code is produces is slow. There's no optimization done. None. So the trade off seems to be: compile fast but slow program, or compile slow but fast program.
Re:The computers are fast, but you don't know it by scarmig on Thursday June 16, 2022 @05:56PM (#31771487)
The trade-off is more of a gradient: e.g. PGO allows an instrumented binary to collect runtime statistics and then use those to optimize hot paths for future build cycles.
Re:The computers are fast, but you don't know it by tester756 on Thursday June 16, 2022 @06:14PM (#31771675)
is this actually this binary?

I mean what if there are features that take significant % of whole time

What if getting rid of them could decrease perf by e.g 4%, but also decrease comp. time by 30%

would it be worth?