147 points · by nikbackm · 9y ago · 53 comments
I believe the site has some malware injected in it. At least the mobile version of it. After a few second it redirected me to some site with a fake Facebook skin.
I just can't believe that one of the biggest monolithic organizations with unlimited budgets and decades of experience developing tools for their own platform(!!) would make such careless mistakes or miss out on rather obvious optimizations. And it also sickens me that random devs out there are wasting hours of their lives doing completely unpaid MS product QA work. At least when jobs are outsourced to the third-world, the laborers are paid something.
The C++ standard doesn't mandate this, but good toolchains do put constant data in a separate read-only segment.
I've never considered that const might have a performance benefit (and mostly just use it as a compile time check). But will consider it in the future.
Would be interesting to see performance benchmarks for the changes made here, as well as applying const in general.
Usually you don't. You just tag your const globals as such and then get on with your day. Once you develop the habit the cost is zero so measuring the benefits isn't necessary.
Is this more of a whole program measured X% regression on some perf benchs, or specific target cases where the codegen is notably worse ?
My recent changes have made the comparison tougher for clang-cl by making the VC++ binaries smaller :-)
IMO `const` should be used liberally: members, locals and other declarations.
When you're on a team and you have a data structure that has const members, it should give that newer/unfamiliar team member pause when they get the compilation error because they added a method that modifies the `const` member. Now they have an opportunity to take a step back and ask "Oh, why was it designed this way? What other assumptions in the code are invalidated if I need to remove the `const`?"
`const` for locals is good for those notorious ten-line functions that over time multiply into a 150-line function. Yes, we should refactor that mega function into something easier to digest. But right now I am trying to figure out this bug: I can see that ^^ up there 'foo' was initialized as a particular value, and down here it looks like it must have changed. Instead of looking through all of the hundred lines of code to see who might've updated 'foo', I know right away that a likely explanation is stack corruption.
This is BTW why I love that rust has opt-in mutability. It feels almost a little silly sprinking `const` thither and yon when it's only a few select places that it's actually un-needed.
Marking globals as const can move them to the read-only segment which has some modest performance improvements, but in most other cases const doesn't affect code-gen at all. Using const prevents programmers from doing certain things, and the compiler enforces that. That suggests that the compiler already knows whether or not programmers are doing those things - it doesn't need a 'const' hint to tell it. And in those cases where it can't tell, the 'const' hint is usually not sufficient for it to depend on.
In short, with the exception of moving globals to the read-only segment I am not aware of any performance improvements from using const.
Check out this subthread: https://news.ycombinator.com/item?id=13356101
As for this comment of yours:
> I can't imagine a single reason to tell people not to use const instance fields.
That's weird, did you not read the blog post? It literally gave you a reason not to, you don't need to imagine anything. If you don't think it's a compelling reason then that's another story, but it's a valid reason.
More importantly, I've never seen an example where adding const would ever decrease CPU performance by any amount at all (other than compiler bugs, which can ruin any language feature). Accordingly, my personal recommendation is that everything that can be const should be. It's an easy thing to do that may help and definitely won't hurt.
> That's weird, did you not read the blog post? It literally gave you a reason not to, you don't need to imagine anything. If you don't think it's a compelling reason then that's another story, but it's a valid reason.
That's an outright compiler bug, not a general language reason. Obviously, it's a valid caveat if you're using that specific compiler and care about that edge case, but it's hardly a general argument.
Ff a function takes a struct (or class) as argument can calls otherfunction(foo.bar), then the constness of foo's bar field matters. The same might apply to fields of this.
https://connect.microsoft.com/VisualStudio/feedback/details/...
struct { const int x; } y = { 1 };