# Environmentally responsible coding

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 05-05-2010
brewbuck
Environmentally responsible coding
How many of you have considered the environmental impact of the code you write, or code you use on a daily basis?

Pulling a number from somewhere, a typical PC might draw 200 watts when doing something intensive. At the wall, the inefficiency of the PSU will cause the actual power to be somewhat higher, let's say 300 watts.

Let's consider some heavily used code. For instance, the JPEG decoder present in all web browsers.

Suppose there are half a billion active Internet users. Let's also suppose that each user uses the web, and views an average of 5000 JPEGs per day (a typical page might have a hundred or more images on it, so this is probably an underestimate). So, the JPEG decoder executes about 2.5 trillion times per day.

Suppose it takes on average, 0.02 seconds to decode a JPEG. Remember, some JPEGs are large, some are small.

Starting from these assumptions, what is the energy impact of a 10% improvement in efficiency of the JPEG decoder?

2.5e12 * 300 watts * 0.002 seconds = 1500 gigajoules.

That's the equivalent of burning about 12000 gallons of gasoline every day. In a year, that's 4.4 million gallons.

Imagine having the ability to spend a few hours optimizing something, and the end result is that 4.4 million fewer gallons of gas are burned each year?

• 05-05-2010
Mario F.
Well, I'm pretty sure I'm not always consuming more energy because I'm using a JPEG decoder while my computer is turned on. I don't think that's how the PSU works in our computers, is it? (honest question. I trully don't know). Besides a gain in performance will most of the time mean an increased expense in processor usage... which would also translate to power consumption, no?

Perhaps efficiency would be a better goal. More time to process if needed be, but at a less overall energy consumption cost.

But looking at those numbers, and assuming a worldwide concern towards environmental impact of energy consumption, imagine the gain if instead of looking at performance we all turned off our computers when we weren't using them. Or, perhaps even more significant to the point at hand, if we curbed our use of JPEGs/Flash/Client-side scripting/etc... in websites.

Performance for the benefit of the environment seems like arguing for animal fur coats because synthetic fur coats take longer to biodegrade.
• 05-05-2010
MK27
Yes, this is one reason why C is ultimately better than C++ even tho it requires more effort on the part of the programmer. :p

I pretty sure it is all trivialized by the amount of "real driving" (read: real driving) that most computer users/owners/programmers do during their normal daily activities.

I can totally see some absurd future greenwash marketing whereby browser X is sold as more environmentally friendly.
• 05-05-2010
brewbuck
Quote:

Originally Posted by Mario F.
Well, I'm pretty sure I'm not always consuming more energy because I'm using a JPEG decoder while my computer is turned on. I don't think that's how the PSU works in our computers, is it? (honest question. I trully don't know). Besides a gain in performance will most of the time mean an increased expense in processor usage... which would also translate to power consumption, no?

I've actually measured it with a wattmeter at the wall. There's a significant difference between an idle CPU and a maxed-out CPU.

As far as performance gain actually taking MORE power, it depends how it's implemented in the first place. It's easy to max out a CPU by doing unnecessary work. Simply removing the unnecessary work doesn't reduce the power, but it does reduce the amount of time that power is required for.

Quote:

Perhaps efficiency would be a better goal. More time to process if needed be, but at a less overall energy consumption cost.
That's strictly more accurate, but it requires knowledge of how much power the various parts of a CPU consume. For instance, if you know that the SSE3 unit takes five times the power as standard floating point, you might choose floating point even if it makes the code run three times slower.

Quote:

But looking at those numbers, and assuming a worldwide concern towards environmental impact of energy consumption, imagine the gain if instead of looking at performance we all turned off our computers when we weren't using them. Or, perhaps even more significant to the point at hand, if we curbed our use of JPEGs/Flash/Client-side scripting/etc... in websites.
You're right of course, but the reality is you simply can't MAKE people do it. But you can tweak a piece of code that's used worldwide, and eventually everybody will be running it, through no deliberate action of their own. You made the difference all by yourself instead of needing to convince a billion people to turn off their computers.
• 05-05-2010
MK27
Quote:

Originally Posted by Mario F.
Client-side scripting

I am guessing that moving the load server side will reduce the "carbon footprint" in your house, but result in an overall increase because of the necessary server upgrades. Maybe you can then sell your carbon credits to the sites you visit, so everybody can think* something has been accomplished.

If you think that people will go for a "less is more web" then maybe you also believe they will go for a "less is more" transit style, or "less is more" packaging at the supermarket.

The last two have been beyond absolute total and complete failures for decades, as would this. People do more gas gussling and consume more pure garbage, per capita, now, than ever before. So again, the only real "accomplishment" to attain would be an advertising gimmick.

* to use the word loosely
• 05-05-2010
Mario F.
I don't believe in anything. I was purposely exposing the irony of the situation. I agree entirely with you two that is just not how the world eventually works. But I felt the need to remember one less JPEG in a 10 JPEGs webpage, will have a greater impact than a 10% increase in the decoder efficiency. The irony resides in the fact that's just not a good solution anymore.
• 05-06-2010
happyclown
I think Javascript and Flash advertisements are the predominant causes of high CPU usage.

I always browse with JS turned off, which makes websites load faster(and reduces the risk of malicious JS embedded in the webpage). I only turn JS on if particular sites require it, like for banking.
• 05-06-2010
dwks
I remember reading in the Linux kernel changelogs at some point that they changed the architecture a little bit so that a wakeup timer no longer fired every second. After this change you could actually let your computer sit there while it was running and get many fewer CPU wakeups per second (theoretically zero, but most other devices wake it up every so often as well). I thought that was a great idea at the time, because if you use powertop for a while you start to realize how much power you save by keeping the CPU in standby mode as long as you possibly can . . . .

I imagine that sort of change had a measurable impact on power consumption (at least for Linux users), because it's in the kernel and it applies all of the time. Anyway, it was just what came to mind when I read this thread.

[I should mention that I probably got half the terms there mixed up, I really don't know very much about the subject . . . .]
• 05-06-2010
VirtualAce
Never thought about it. Probably won't a few seconds after reading this either.

Most oil drums: 55 US gallons
Last estimate of leak in the Gulf: ~5000 barrels a minute or 275,000 gallons per minute, 16,500,000 per hour, 396,000,000 per day.

Total required for 1 hour of use for half a billion users with usage of 12,000 gallons per day: 500 gallons per hour
Percent of power required out of total in one hour given a flow rate of 275,000 gallons per minute (16,500,000 per hour) and usage of 500 per hour for half a billion users: 500 / 16,500,000 = 3.030~030 * e^-5%.

So that one leak in the Gulf produces enough oil in one hour to power half a billion users with a usage of 12,000 gallons per day for 33,000 (396,000,000 / 12,000) days or 90.14 years.

And besides electrical power isn't normally produced from oil, it is produced from coal and/or nuclear and/or water.
• 05-10-2010
Brafil
Microsoft should really do something for the environment.
• 05-10-2010
MK27
Quote:

Originally Posted by Brafil
Microsoft should really do something for the environment.

So should the makers of Hostess potato chips, etc, but I think the most you will learn about "social responsibility" in business school is how to hire a PR firm to clean your exposure/profile while minimizing any other possible expenditure.

Capitalist enterprise, by it's very nature, is simply not capable of "doing something for the environment". If this were not the case, it would have happened by now, but it has not and it won't be in the future, either.
• 05-11-2010
VirtualAce
Ok a little update on the numbers. Recent reports say the leak is around 4 million gallons. That does not equate to the aforementioned 5000 barrels a minute. So once again the first reports coming out were completely exaggerated and the more recent reports are still exaggerated but getting closer to the actual number...if that is even possible given the conditions.
• 05-11-2010
brewbuck
Quote:

Originally Posted by MK27
So should the makers of Hostess potato chips, etc, but I think the most you will learn about "social responsibility" in business school is how to hire a PR firm to clean your exposure/profile while minimizing any other possible expenditure.

Part of the point I'm making is because of the nature of software -- created once and then deployed without bound -- a single developer can make a large difference. Even if that difference is insignificant on a global energy balance, the rate of return per person involved is huge.

How much impact can you make by selling your car and riding a bike? How much by installing energy efficient appliances? By turning things off and unplugging them when not in use? Can you make 4.4 million gallons difference?

I'm not saying that "green" programming will save the world.
• 05-11-2010
MK27
Quote:

Originally Posted by brewbuck
Part of the point I'm making is because of the nature of software -- created once and then deployed without bound -- a single developer can make a large difference.

Sure, and you could write CLI interfaces more too, that would make a way more huge difference in terms of resource usage. But let's be realistic -- the environment is not worth people having to use the command line! :p
• 05-12-2010
Brafil
Course not. That would require many hours of additional computer courses for most of the users, which means more fuel is wasted for transport.

But maybe... Microsoft could make a light windows system with nice graphics (XP-Style) and low system requirements...
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last