User: Password:
|
|
Subscribe / Log in / New account

Redesigning Python's named tuples

LWN.net needs you!

Without subscribers, LWN would simply not exist. Please consider signing up for a subscription and helping to keep LWN publishing

By Jake Edge
August 23, 2017

Deficiencies in the startup time for Python, along with the collections.namedtuple() data structure being identified as part of the problem, led Guido van Rossum to decree that named tuples should be optimized. That immediately set off a mini-storm of thoughts about the data structure and how it might be redesigned in the original python-dev thread, but Van Rossum directed participants over to python-ideas, where a number of alternatives were discussed. They ranged from straightforward tweaks to address the most pressing performance problems to elevating named tuples to be a new top-level data structure—joining regular tuples, lists, sets, dictionaries, and so on.

A named tuple simply adds field names for the entries in a tuple so that they can be accessed by index or name. For example:

    >>> from collections import namedtuple
    >>> Point = namedtuple('Point', ['x', 'y'])
    >>> p = Point(1,2)
    >>> p.y
    2
    >>> p[1]
    2
The existing implementation builds a Python class implementing the named tuple; it is the building process that is the worst offender in terms of startup performance. A bug was filed in November 2016; more recently the bug was revived and various benchmarks of the performance of named tuples were added to it. By the looks, there is room for a good bit of optimization, but the fastest implementation may not be the winner—at least for now.

To some extent, the current named tuple implementation has been a victim of its own success. It is now routinely used in the standard library and in other popular modules such that its performance has substantially contributed to Python's slow startup time. The existing implementation creates a _source attribute with pure Python code to create a class, which is then passed to exec() to build it. That attribute is then available for use in programs or to directly create the named tuple class by incorporating the source code. The pull request currently under consideration effectively routes around most of the use of exec(), though it is still used to add the __new__() function to create new instances of the named tuple class.

After Van Rossum's decree, Raymond Hettinger reopened the bug with an explicit set of goals. His plan was to extend the patch set from the pull request so that it was fully compatible with the existing implementation and to measure the impact of it, including for alternative Python implementations (e.g. PyPy, Jython). But patch author Jelle Zijlstra wondered if it made sense to investigate a C-based implementation of named tuples created by Joe Jevnik.

Benchmarks were posted. Jevnik summarized his findings about the C version as follows: "type creation is much faster; instance creation and named attribute access are a bit faster". Zijlstra's benchmarks of his own version showed a 4x speedup for creating the class (versus the existing CPython implementation) and roughly the same performance as CPython for instantiation and attribute access. Those numbers caused Zijlstra to suggest using the C version:

Joe's cnamedtuple is about 40x faster for class creation than the current implementation, and my PR only speeds class creation up by 4x. That difference is big enough that I think we should seriously consider using the C implementation.

There are some downsides to a C implementation, however. As the original bug reporter, Naoki Inada, pointed out, maintenance is more difficult for C-based code. In addition, only CPython can directly benefit from it; alternative language implementations will either need to reimplement it or forgo it.

Class creation performance is only one area that could use improvement, however. Victor Stinner noted that accessing tuple values by name was nearly twice as slow when compared to the somewhat similar, internal PyStructSequence that is used for things like sys.version_info. It would be desirable for any named tuple upgrade to find a way to reduce the access-by-name overhead, several said. In fact, Giampaolo Rodolà pointed out that the asyncio module could serve nearly twice as many requests per second if the performance of PyStructSequence could be attained.

But Rodolà would like to go even further than that. He proposed new syntax that would allow the creation of named tuples on the fly. He gave two possibilities for how that might look:

    >>> ntuple(x=1, y=0)
    (x=1, y=0)

    >>> (x=1, y=0)
    (x=1, y=0)

Either way (or both) would be implemented in C for speed. It would allow named tuples to be created without having to describe them up front, as is done now. But it would also remove one of the principles that guided the design of named tuples, as Tim Peters said:

How do you propose that the resulting object T know that T.x is 1. T.y is 0, and T.z doesn't make sense? Declaring a namedtuple up front allows the _class_ to know that all of its instances map attribute "x" to index 0 and attribute "y" to index 1. The instances know nothing about that on their own, and consume no more memory than a plain tuple. If your `ntuple()` returns an object implementing its own mapping, it loses a primary advantage (0 memory overhead) of namedtuples.

Post-decree, Ethan Furman moved the discussion to python-ideas and suggested looking at his aenum module as a possible source for a new named tuple. But that implementation uses metaclasses, which could lead to problems when subclassing as Van Rossum pointed out.

Jim Jewett's suggestion to make named tuples simply be a view into a dictionary ran aground on too many incompatibilities with the existing implementation. Python dictionaries are now ordered by default and are optimized for speed, so they might be a reasonable choice, Jewett said. As Greg Ewing and others noted, though, that would lose many of the attributes that are valued for named tuples, including low memory overhead, access by index, and being a subclass of tuple.

Rodolà revived his proposal for named tuples without a declaration, but there are a number of problems with that approach. One of the main stumbling blocks is the type of these on-the-fly named tuples—effectively each one created would have its own type even if it had the same names in the same order. That is wasteful of memory, as is having each instance know about the mapping from indexes to names; the current implementation puts that in the class, which can be reused. There might be ways to cache these on-the-fly named tuple types to avoid some of the wasted memory, however. Those problems and concern that it would be abused led Van Rossum to declare the "bare" syntax (e.g. (x=1, y=0)) proposal as dead.

But the discussion of ntuple(x=1, y=0) continued for a while before seemingly running aground as well. Part of the problem is that it combines two things in an unexpected way: declaring the order of the fields in the named tuple and using keyword arguments where order should not matter. For the x and y case, it is fairly clear, but named tuples could be used for types where the order is not so clear. As Steven D'Aprano put it:

I don't see any way that this proposal can be anything by a subtle source of bugs. We have two *incompatible* requirements:
  • we want to define the order of the fields according to the order we give keyword arguments;
  • we want to give keyword arguments in any order without caring about the field order.
We can't have both, and we can't give up either without being a surprising source of annoyance and bugs.

As far as I am concerned, this kills the proposal for me. If you care about field order, then use namedtuple and explicitly define a class with the field order you want. If you don't care about field order, use SimpleNamespace.

He elaborated on the ordering problem by giving an example of a named tuple that stored the attributes of elementary particles (e.g. flavor, spin, charge) which do not have an automatic ordering. That argument seemed to resonate with several thread participants.

So it would seem that a major overhaul of the interface for building named tuples is not likely anytime soon—if ever. The C reimplementation has some major performance benefits (and could presumably pick up the PyStructSequence performance for access by name), but it would seem that the first step will be to merge Zijlstra's Python-based implementation. That will allow for a fallback with better performance for alternative implementations, while still leaving open the possibility of replacing it with an even faster C version later.


(Log in to post comments)

The moral dimension of performance

Posted Aug 25, 2017 22:08 UTC (Fri) by ncm (subscriber, #165) [Link]

Issues around the performance of Python and programs written in it have far wider consequences than startup time. During all the time any Python program is running, its host machine is consuming power that typically depends on pumping CO2 into the atmosphere. If most of that power is wasted, the effects go far beyond extra money to buy it, or to operate extra servers, or users who wait a little longer. The carbon footprint of a Python program that runs throughout a data center, or many data centers, adds up.

The question arises: As the author of a widely-used Python program, how many species extinctions are you personally responsible for, as a consequence of having choosen Python? (Similarly, for PHP or Ruby.)

Our planet, all of us, are in the early stages of a mass extinction of catastrophic proportions. Estimates of current populations of birds and insects are already down more than 50% from only a few decades ago [1]. Until wind and solar generating capacity can replace coal, oil, and gas, which will take decades more, energy wasted on inefficiency directly harms Earth's biosphere, and the survival prospects of any number of species. Of course the greatest number of eliminated species will be insects (just because there were and still are so many), but the whole web of life, plants, animals, and microbes, depends on those insects.

Humans do not stand apart from nature. Whatever threatens the biosphere threatens the survival prospects of your grandchildren. As world fisheries collapse and formerly fertile farmland stops producing (whether from climate change or failure of pollination) wars will be fought over the food production capacity remaining. How many war casualties can be attributed to your program? There will be plenty to go around.

If you have a choice of which language to use for code that will run widely, consider not using Python, PHP, or Ruby. If you have any opportunity to make Python or other very slow language faster, even at the cost of pain for users, do. No amount of programming inconvenience matches the loss of one grandchild, or one species.

[1] google: "wild animal populations down"

The moral dimension of performance

Posted Aug 26, 2017 12:41 UTC (Sat) by excors (subscriber, #95769) [Link]

> As the author of a widely-used Python program, how many species extinctions are you personally responsible for, as a consequence of having choosen Python?

As far as I can tell from the numbers, approximately none. I agree there's a serious problem and it needs to be solved somehow, but I'm not convinced programming language performance will make any appreciable difference.

The IPCC says e.g. there is "high confidence that climate change will contribute to increased extinction risk for terrestrial and freshwater species over the coming century" <http://www.ipcc.ch/pdf/assessment-report/ar5/wg2/WGIIAR5-...>; there is a lot of uncertainty over exact numbers but it's apparently reasonable to assume "approximately 20-30% of the plant and animal species assessed to date are at increasing risk of extinction as global mean temperatures exceed a warming of 2-3°C above preindustrial levels".

The Paris Agreement aims to "hold the increase in the global average temperature to well below 2°C above pre-industrial levels" (while noting with "serious concern" that current pledges were insufficient to reach even that relatively high target), so the "2-3°C" range is a reasonable point to work from.

In 2011, Google was reported to use about 0.01% of the world's electricity. They've probably gone up since then, but apparently electricity is only roughly 10% of total energy consumption, so let's say it's still around 0.01% of the world's energy.

Estimates for total number of species in the world seem to vary a lot (and depend on what you count as a species), but could be around 10 million.

That means all of Google's data centers are responsible for increased risk of extinction for perhaps 0.01%*30%*10M = 300 species. If your Python program is using the equivalent of 0.3% of Google's entire compute power - which I suspect is unlikely - and you rewrite it in an infinitely fast language, then you've saved one species from the increased risk. (Not even from guaranteed extinction, just risk. And it was probably an insect or a fungus anyway, not a cute mammal.)

For comparison, production of paper apparently makes up around 2.5% of the world's energy consumption. If Python lets you be a more productive programmer, and that lets you end up building some cool technology that reduces people's paper usage by an average of 0.001%, then you'll have saved one species. That might be a more effective area to focus on.

The moral dimension of performance

Posted Aug 26, 2017 14:30 UTC (Sat) by sdalley (subscriber, #18550) [Link]

Your consideration of the wider moral dimensions has my respect. I too, care about the world we're leaving behind. Obviously, efficient energy use is no bad thing.

However, the broader argument is founded on a bad assumption, that less energy use necessarily means less biosphere damage.

Insisting on this will condemn the poorer two thirds of the world to ongoing poverty. And the worst biosphere damage is taking place in poorer countries. Chopping trees for firewood, and having to burn cow dung, are *not* environmentally friendly.

> Until wind and solar generating capacity can replace coal, oil, and gas, which will take decades more, energy wasted on inefficiency directly harms Earth's biosphere

Unfortunately, wind and solar, harnessing as they do dilute, diffuse and intermittent sources of energy and hence requiring large areas and resource consumption, end up having a much large environmental footprint than say, nuclear power. Germany's antinuclear Energiwiende, which has set its hopes on wind, solar, and environmentally destructive "biomass", has been running to stand still in terms of CO2 intensity reduction.

Germany: ~400 g/kWh, thanks to its lignite and gas.
France: ~60g/kWh, thanks to its nuclear and hydro.
See [0].

Solar power with battery storage comes out at around 200g/kWh [1] when you take the whole chain into account. Nuclear is a tenth of that.

The key is to generate cheap and low-impact energy, rather than expensive and unreliable energy. You might be interested in [2].

[0] https://electricitymap.tmrow.co
[1] https://medium.com/@ActinideAge/batteries-emissions-7e54f...
[2] http://www.environmentalprogress.org/our-story/

The moral dimension of performance

Posted Aug 31, 2017 11:07 UTC (Thu) by Wol (guest, #4433) [Link]

> Insisting on this will condemn the poorer two thirds of the world to ongoing poverty. And the worst biosphere damage is taking place in poorer countries. Chopping trees for firewood, and having to burn cow dung, are *not* environmentally friendly.

While the big picture is rarely simple, trees and cow dung are not ecofriendly how?

Okay, I'll answer myself, deforestation destroys soil and creates deserts, and cow dung presumably similar.

What burning trees and cow dung does NOT do is add to the CO2 load - burning biomatter simply drives the CO2 cycle round a bit faster. The global warming problem is primarily driven by burning fossil fuels and adding "new" carbon to the cycle.

Cheers,
Wol

The moral dimension of performance

Posted Aug 31, 2017 20:23 UTC (Thu) by pboddie (guest, #50784) [Link]

Apparently, the craze for burning wood pellets in the UK has already driven unsustainable tree-felling in the US, thereby creating a scheme where people can claim that there is a natural cycle involved and is somehow sustainable in the long term, but where those burning the pellets are effectively creating a mountain of carbon "debt" for future generations to deal with. And let us not even consider how all these pellets have to be shipped to the UK: I doubt that they are using sailing ships for that.

Making the carbon dioxide "go round a bit faster" would be quite a trick to pull off. But instead of insisting that electricity and heat must involve burning things, the UK (and everyone else) would be better off embracing proper renewables.

The moral dimension of performance

Posted Sep 1, 2017 9:10 UTC (Fri) by Wol (guest, #4433) [Link]

That pretty much exemplifies what I was getting at.

Burning wood pellets is CO2-neutral. "Going round a bit faster" simply means that the "tree to CO2" step occurs faster than it would have in nature, but it would have happened naturally.

Using fossil fuel to transport unsustainable wood-chips for use as fuel ... well ... penny wise and pound foolish as I would put it.

That's why I think "waste to power" is a good idea (never mind that I was a NIMBY over the plant they built about a mile from my house - they chose to build it in one of the *greenest* (recycling wise) and poorest London Boroughs, and the majority of the waste burnt comes from boroughs too rich to bother with recycling). Surely it's better to burn plastic as fuel close to where it becomes rubbish, and replace it with fresh plastic from oil, than invest heavily in fuel-expensive technologies to recycle it?

As for renewables, I very much agree. I've got solar panels. But there was an interesting article in the FT about how even there we are being penny-wise and pound-foolish. Irregular supply has a cost, and solar shuts down at night or cloudy weather, wind shuts down when it's still or high. And these costs are being unfairly externalised onto the fossil generators ... I still think it's a good idea, but it shows how accurately costing things is a nightmare.

Cheers,
Wol

The moral dimension of performance

Posted Sep 1, 2017 14:45 UTC (Fri) by pboddie (guest, #50784) [Link]

Irregular supply has a cost, and solar shuts down at night or cloudy weather, wind shuts down when it's still or high.

Amusingly, while people still insist that solar is not viable "at higher latitudes" especially in the UK, adoption spreads further north regardless. So you have people in the southern half of Norway adopting solar for purely economic reasons, even though most of Norway is further north than most of the UK. Even "passive" solar heating is viable in the UK, or at least worthwhile. And the technology only gets better, which one perhaps wouldn't know if one only listened to political and media dinosaurs.

And these costs are being unfairly externalised onto the fossil generators

Firstly, since the fossil generators have never had to pay for their own substantial impacts (rather like the nuclear industry), I would say it is about time. Secondly, supply flexibility is a good thing. The UK will have to confront this in other areas, such as its dependency on natural gas for many things, which is why those dinosaurs promote the status quo and ruinous things like fracking.

The moral dimension of performance

Posted Sep 2, 2017 23:40 UTC (Sat) by sdalley (subscriber, #18550) [Link]

> Amusingly, while people still insist that solar is not viable "at higher latitudes" especially in the UK, adoption spreads further north regardless. So you have people in the southern half of Norway adopting solar for purely economic reasons

Yes, solar is "viable" at high latitudes, so long as you pay enough subsidies. Whether you get useful and timely amounts of power and CO₂ reductions is far less certain. The trouble with Norway is:

- Norway is already almost all very-low-carbon hydroelectricity. Solar is not going to reduce CO₂ significantly, rather the reverse when you take the full PV panel lifecycle emissions into account.
- The motion of the sun is more azimuthal (sideways around the horizon) than altitudinal (crossing overhead). Taking best advantage of the long summer days thus requires the panels to track azimuth adding mechanical complexity and precluding a fixed mounting on the roof.
- The demand is highest during winter, when the sun is weak or absent, rather than the summer. Unfortunately, hydro inflows are also low during the winter, and peak in early summer when solar is also a maximum. Hydro storage is large (in proportion to the population), but there are already plenty of other demands on it, not least from Danish wind generation.

Passive solar heating, at 80% efficiency rather than 20% for PV, obviously has to be a good idea, I agree.

>the fossil generators have never had to pay for their own substantial impacts (rather like the nuclear industry)

Right on fossil generators, completely wrong on nuclear power. Nuclear is absolutely lowest-footprint per kWh of all generation, including wind/solar.
- It has the lowest deaths per kWh [1]. Including Chernobyl.
- It has the least waste per kWh, by far. As an example, take the 29-year lifetime of Connecticut Yankee. It generated 12.7 gigawatt-years of juice, and the entire high-level waste stream, which is solids, sits tidily in 43 dry casks. See [2]. Calculating the equivalent stack of solar PV panels is left as an exercise for the reader.
- All of its waste has to be rigorously accounted for and appropriately stored, and payment for this is required in advance from a levy on each kWh generated into a managed fund.
- It has among the lowest full-lifecycle CO₂ per kWh, ~20g. This is less than solar, comparable to wind, and only hydro is less.[3]
- Compared to wind and especially solar, nuclear subsidies per kWh are negligible. See [4].
[1] https://www.nextbigfuture.com/2016/06/update-of-death-per...
[2] http://www.connyankee.com/html/about_cy.html
[3] http://www.world-nuclear.org/uploadedFiles/org/WNA/Public...
[4] https://spectrum.ieee.org/energywise/energy/policy/how-mu...

The insanity of first Germany, now even France and South Korea, wanting to do away with the strongest decarbonization tool in the box, atomic power, passes belief. I guess there's no accounting for fashion...

The moral dimension of performance

Posted Sep 3, 2017 10:23 UTC (Sun) by pboddie (guest, #50784) [Link]

Yes, solar is "viable" at high latitudes, so long as you pay enough subsidies.

But the economics are evolving all the time. And my point was that if a country at a higher latitude than the UK can use solar photovoltaic generation, even if it is just one component of supply, it makes the excuses used in places like the UK seem pretty weak.

Unfortunately, hydro inflows are also low during the winter, and peak in early summer when solar is also a maximum. Hydro storage is large (in proportion to the population), but there are already plenty of other demands on it, not least from Danish wind generation.

Yes, Norway has to import energy when the country's electricity suppliers have managed to run down the reservoirs. I have read arguments about this being done unnecessarily because there are no incentives for those suppliers to manage supply responsibly. When those companies can just pass on power generated elsewhere by offering competitive "market rates" rather than commit to a price, and when customers can be led into thinking that "market rates" are the pricing benchmark, there are no penalties to those suppliers when they have to buy more expensive, often fossil-fuel-generated, power from elsewhere.

Compared to wind and especially solar, nuclear subsidies per kWh are negligible.

What about the decommissioning costs? The taxpayer gets quoted super-low numbers which turn out to be substantially larger (looking at the UK Nuclear Decommissioning Authority estimates over time). Still, I guess it keeps people in work.

(I see that the article you reference about mortality rates is the usual "but what about" kind of thing that often appears when people have negative things to say about nuclear energy. And suddenly, everyone is an actuary.)

The moral dimension of performance

Posted Sep 6, 2017 22:29 UTC (Wed) by sdalley (subscriber, #18550) [Link]

> What about the decommissioning costs?
Decommissioning costs for a nuclear power station, as I said before, must be funded up-front. These are completely different, and far less, from decommissioning and cleanup costs for the 70 years potpourri of nuclear weapons reactor R&D and the whole historical legacy that the UK NDA is having to deal with. The instance of Connecticut Yankee previously mentioned, cost $850million from premature-shutdown to greenfield-decommissioned, and the somewhat larger Maine Yankee cost $500 million. [1]. If they had been allowed to run for their design lifetimes the (compulsory) decommissioning funds would have been ample.

Of course, there is no limit to the costs when they are driven by whipped-up nuclear fears and being fed with a steady diet of nuclear falsehoods. FoEs of the Earth, and Greenpeace, take a bow.... I just want to do my bit to correct the record.

> the article you reference about mortality rates is the usual "but what about" kind of thing
That article is more of a meta-study of different primary mortality studies, taking into account various factors so that you can can get a multi-faceted overview. What's your point? Are you saying that this is somehow dishonest or that the numbers are incorrect?

If you have the time and have an open mind, here are two very educational films: Radioactive Wolves [2], and Pandora's Promise [3]

[1] http://www.meredithangwin.com/yankee_decommissioning.pdf
[2] https://www.youtube.com/watch?v=2Cu-80jzC44
[3] https://www.youtube.com/watch?v=QiNRdmaJkrM

The moral dimension of performance

Posted Sep 7, 2017 14:59 UTC (Thu) by pboddie (guest, #50784) [Link]

Decommissioning costs for a nuclear power station, as I said before, must be funded up-front. These are completely different, and far less, from decommissioning and cleanup costs for the 70 years potpourri of nuclear weapons reactor R&D and the whole historical legacy that the UK NDA is having to deal with.

Unfortunately, "must be funded up front" is one of those things people don't like to practise. It is true that the history of nuclear development threads together weapons research, power generation and also other nuclear applications (isotope production for medical applications, for instance, also something that was done at Windscale, if I remember correctly.) But maybe the facilities that were actually designed and run as power generation facilities are relatively inexpensive to decommission.

However, there always seems to be a component of R&D and figuring things out as they happen even in supposedly tried-and-tested designs. One of the things that people advocating "radical" designs insinuate is that not enough R&D has been done to smooth the way for their own pet projects, whether it involves thorium, "pebble bed" reactors, "molten salt" reactors, insert buzzwords here. But I would say that actually quite a bit has already been done, but it is arguably the case that it wasn't done responsibly. The issue then is how the nuclear industry can be trusted to do it responsibly in future.

What's your point? Are you saying that this is somehow dishonest or that the numbers are incorrect?

I would say it is dishonest to start off talking about Chernobyl and then bring in topics like obesity. I've seen plenty of this kind of argument before: "Oh, we'll never really know because it is all so hard to measure and who cares if it takes a few days off people's lifespans, anyway? Oh, and what about...?" As I note above, this doesn't establish a track record of confidence.

Anyway, my point, if I even remember what it was supposed to be, was that renewables (with the exception of hydroelectric power) have by no means had the benefits that other technologies have enjoyed over the years, mostly because they were subject to ridicule for decades (rhetoric that you still get in political debate) and have required technological progress to become competitive with traditional power sources. Even now, countries like the UK and Norway (the poster child for energy policy hypocrisy) would rather invest in oil and gas than the renewable technologies that will eventually be powering their societies.

The moral dimension of performance

Posted Sep 3, 2017 23:20 UTC (Sun) by renox (subscriber, #23785) [Link]

> All of its waste has to be rigorously accounted for and appropriately stored, and payment for this is required in advance from a levy on each kWh generated into a managed fund.

It's funny that you think that the decommissioning/waste handling price has been accurately estimated given that usually building a nuclear central cost two or three times the estimate..

The moral dimension of performance

Posted Sep 4, 2017 13:53 UTC (Mon) by Wol (guest, #4433) [Link]

The problem is peoples' knee-jerk reaction when people hear the words "nuclear waste". Yes, radiation is hazardous but people *choose* to sunbathe! That's probably far more dangerous than sitting in the deckchairs at Sea/Windscale (the site of the UK's nuclear waste processing plant, for those who don't know). Even *including* all the leaks, it's still a lot less radioactive than Aberdeen, and there are Cornish beaches where you can give yourself a real radioactive burn just by picking up pebbles from the beach ...

Once the worst "hot" radioactivity has been allowed to burn off, what's left is probably much safer than what nature throws at us, even after just 50 years or so.

And while most of our generation is currently U-235/Pu-239 based, I'm given to understand that if we used Thorium reactors, firstly we could chuck all out U/Pu waste into the Thorium feedstock, and secondly once the "hot" radioactivity is gone from Thorium waste well, that's pretty much *all* the radioactivity gone.

While we need to be careful, we seem to be demanding far higher safety standards from the nuclear industry than nature itself provides ...

Cheers,
Wol

The moral dimension of performance

Posted Sep 4, 2017 14:59 UTC (Mon) by anselm (subscriber, #2796) [Link]

The problem here is that, as far as many people are concerned, nothing less than perfect safety will do when it comes to nuclear plants, and since they can't have perfect safety, they don't want anything to do with nuclear plants at all. (The idea that radioactivity occurs in nature is probably as foreign to many people as the idea that organically-grown food contains genes.)

Of course apart from no nuclear reactors, people also want to stop global warming and have enough cheap electricity for everyone at all times. This is one of those situations where you get to pick at most two out of three.

The moral dimension of performance

Posted Sep 4, 2017 15:22 UTC (Mon) by farnz (subscriber, #17727) [Link]

The thing that makes me sigh when it comes to "nuclear power is dangerous radioactivity!" crew is that (based on sources like this report from a US national laboratory) the radiation levels emitted by a coal power plants and its waste ash are higher than those permitted from a fission power plant.

In other words, replacing coal with fission is a net win for radiation exposure alone...

The moral dimension of performance

Posted Sep 2, 2017 10:08 UTC (Sat) by sdalley (subscriber, #18550) [Link]

> Burning wood pellets is CO2-neutral. "Going round a bit faster" simply means that the "tree to CO2" step occurs faster than it would have in nature, but it would have happened naturally.

Trouble is, it only gets you half-way round a bit faster. The CO₂-to-tree step takes just as long, 50 years or so, (and indeed might happen only partially, see [1] for some ugly real-life examples). Meanwhile the extra greenwashed CO₂ is happily floating around warming the place up.

> I've got solar panels.

Very nice. But honestly, would they have made financial sense if there was no installation subsidy or solar generation premium, and you only got the grid spot price for any surplus? I've got my doubts.

> Irregular supply has a cost

You're certainly right there. Wind and solar output is about as smooth as a porcupine's bottom [2], and because actual grid load varies smoothly, other generators have to vary in a compensating manner. This can give thermal plant a real hammering [3]. But why should renewables care? They don't have to maintain the plant they're knocking about, they can free-load on the grid instead, sell with mandated priority, and probably get paid a fat FIT as well! Once the penetration of wind/solar exceeds about 20% this starts to get really tricky from a system point of view. No wonder conventional generators are losing money - the playing field is wildly unlevel.

[1] http://www.fern.org/sites/fern.org/files/upinflames_inter... .
[2] http://euanmearns.com/wind-power-denmark-and-the-island-o...
[3] http://www.nrel.gov/docs/fy12osti/55433.pdf

The moral dimension of performance

Posted Sep 2, 2017 22:40 UTC (Sat) by pboddie (guest, #50784) [Link]

But why should renewables care? They don't have to maintain the plant they're knocking about, they can free-load on the grid instead, sell with mandated priority, and probably get paid a fat FIT as well!

I thought that the UK government had abolished feed-in tariffs or made them significantly less attractive, probably so that they can give tax breaks to those poor, unprofitable "conventional generators" and fund (through guarantees and mandated pricing) nuclear projects that will be late, over budget, and probably defective.

I don't doubt that certain kinds of renewables pose challenges to the network. But these challenges will need to be faced anyway, and it isn't as if storage technology will be standing still while all this takes place.

The moral dimension of performance

Posted Aug 26, 2017 16:17 UTC (Sat) by flussence (subscriber, #85566) [Link]

There was one anecdote floating around on the web about how fixing a single bug in the Turbo Pascal (or was it C?) compiler sped it up enough to save an enormous amount of wasted time (and kWh) across its userbase.

I think you're wrong. The planet *is* on course to becoming unable to sustain life, but it'll be the browser industry that delivers us unto oblivion. Not Python, PHP, Ruby or even Perl. Javascript is burning the planet: spying Javascript we didn't ask for, antivirus Javascript we use to stop that other Javascript from running, trendy Javascript that compels us to throw away computers by the billions because we need 64 bit address spaces and the latest quad-core luxury ultrabooks to cope with ever more greedy Javascript text editors and Javascript instant messaging and Javascript content consumption.

(This comment was posted using Dillo. I can't fix the world but I'll still spite it to make a point.)

The moral dimension of performance

Posted Aug 26, 2017 22:23 UTC (Sat) by anselm (subscriber, #2796) [Link]

The planet *is* on course to becoming unable to sustain life, but it'll be the browser industry that delivers us unto oblivion.

Nope. Bitcoin and friends. The aggregated electricity consumption of all Bitcoin mining operations comes to about the same as that of the whole nation of Ireland – and for what? Making ransomware writers happy and buying drugs on the Darknet.

The moral dimension of performance

Posted Aug 28, 2017 19:31 UTC (Mon) by flussence (subscriber, #85566) [Link]

Oh don't worry, browsers will have that market cornered soon.

You'll soon be able to read webpages ad-free by letting them mine in your browser, and thanks to Web Workers it'll happen invisibly in the background. So convenient! Ad networks are going to *love* WebCL.

The moral dimension of performance

Posted Sep 4, 2017 21:59 UTC (Mon) by flussence (subscriber, #85566) [Link]

I was being facetious here, but a few days later I found out there are large sites and ad networks guilty of already doing this. Of course there are. Teach me to have any faith in humanity…

The moral dimension of performance

Posted Aug 31, 2017 12:10 UTC (Thu) by davidgerard (guest, #100304) [Link]

Nope. Bitcoin and friends. The aggregated electricity consumption of all Bitcoin mining operations comes to about the same as that of the whole nation of Ireland – and for what? Making ransomware writers happy and buying drugs on the Darknet.

It's a huge waste, but mostly doesn't pump out gratuitous carbon. Most bitcoin mining is using cheap Chinese renewables. The Bitmain building in Xinjiang with 75% of the mining capacity runs off wind and solar; most of the rest takes advantage of overbuilt hydro. There are a few that run off overbuilt coal-fired plants (e.g., Ordos, subject of recent bitcoin mine photo essays, which has about 4% of hashpower).

The moral dimension of performance

Posted Aug 30, 2017 17:49 UTC (Wed) by aigarius (subscriber, #7329) [Link]

Python is not much slower than other languages in execution. But it is much faster in writing. And people have far more impact on environment that a few kWh of electricity. By needing more man hours to write the same program, you are killing species. Save the world - program in Python.

The moral dimension of performance

Posted Aug 30, 2017 19:38 UTC (Wed) by smckay (guest, #103253) [Link]

I don't consume more CO2 when coding Java vs. Python.

The moral dimension of performance

Posted Aug 30, 2017 20:51 UTC (Wed) by sfeam (subscriber, #2841) [Link]

consume CO2? You mean like by pouring fizzy water into your single malt before drinking it?

The moral dimension of performance

Posted Aug 31, 2017 19:05 UTC (Thu) by smckay (guest, #103253) [Link]

I meant "produce", or maybe more accurately "have CO2 emissions attributable to me", but I do drink a lot of soda.

The moral dimension of performance

Posted Sep 1, 2017 10:47 UTC (Fri) by edeloget (subscriber, #88392) [Link]

Small performance improvements on heavily used code have large practical impacts on energy consumption. If one million machine, each consuming 250W/h, see a 1 s improvement in the handling of a particular repeated 1 minute-long task, that's an collective economy of 70kW each time they execute the script, and that amount to 10 MW over the course of one single day.

Given how much Python is used today, how much energy can be saved if we make it 0.1% faster ?

I'm not sure the time spent by a human to write that change will ever have the impact.

For the record, although I cannot find the reference again, Andreï Alexandrescu of Facebook once stated that a millisecond improvement on each page loading was worth millions of dollars in electricity alone. He spent most of his tenure at Facebook working on how to optimize the various tools Facebook was using to serve pages.

Program performance matters.

The moral dimension of performance

Posted Sep 2, 2017 8:42 UTC (Sat) by aigarius (subscriber, #7329) [Link]

Sure, improving speed of Python is a good thing. The original poster was arguing that by writing *anything* in Python you are being responsible for killing nature. For most of software the execution speed of a language is nowhere near the performance bottleneck - there are network and disk delays, there is user input latency and coordination with other systems. So my counterargument is that by pushing people from easy to write and maintain Python to some faster, but harder language you save milliseconds per execution while costing man-weeks or man-months in development time which means more food being prepared for the programmers, more driving to work and a bunch of other energy expenditure that easily dwarfs even millions of seconds of extra CPU time.

The moral dimension of performance

Posted Sep 2, 2017 18:11 UTC (Sat) by mb (subscriber, #50428) [Link]

>each consuming 250W/h,
>that's an collective economy of 70kW each time they execute the script,
>and that amount to 10 MW over the course of one single day.

Your usage of Watts does not make sense at all.

>Program performance matters.

That partially right. But it does not matter most of the time. Most code is not executed that frequently.

The moral dimension of performance

Posted Sep 2, 2017 19:03 UTC (Sat) by karkhaz (subscriber, #99844) [Link]

I've been following this thread with interest, hoping that somebody would post some actual numbers. (disclaimer, I don't have any either). The grandparent comment posted some energy numbers per time of running a python script, but I doubt anybody knows how much time is spent running python scripts.

At some point, I became very interested in working out what changes in my lifestyle I could make to help protect the environment. Even incredibly simple decisions turn out to be insanely complicated to work out---things like "given the choice, should I dry my hands with the electric dryer or using paper towels"? The answers are often very counterintuitive and I'm now very skeptical of claims that doing X is better for the environment than Y. Or you have studies like [0] that focus on one tiny area of life (disposable vs. reusable cups), and even that doesn't tell you which is "better" for the environment but focuses only on energy usage (neglecting, for example, waste and pollution during manufacture; the renewability of raw materials for each kind of cup, and whether they can be recycled; etc).

[0] http://sustainability.tufts.edu/wp-content/uploads/Compar...

More on-topic, I have colleagues who have done academic work on automatically removing fence/barrier instructions from programs (in a safe way, i.e. the compiler was being conservative when it inserted them) because fences use a lot of power on a CPU or GPU (the whole cache needs to get flushed, all values need to be committed to memory, etc) and a big motivation is saving power in data centers. They generally do have numbers, because it's a tiny specialized problem that can be easily measured.

At a glance, both sides in this thread seem meaningless without further context. Programmer time probably wastes more energy if the program doesn't run on many devices, but if the program is running in a data center then an epsilon-sized energy saving might dwarf any number of programmer-hours. But I honestly haven't worked out the numbers myself, and I don't know what proportion of code in the wild runs on data centers versus running on mobile phones versus running in a traffic light. These things (and many, many more) would need to be known before making the claim that X saves more power than Y. I wish we had better data.

The moral dimension of performance

Posted Sep 1, 2017 21:33 UTC (Fri) by HelloWorld (guest, #56129) [Link]

> Python is not much slower than other languages in execution.
Seriously?
https://benchmarksgame.alioth.debian.org/u64q/compare.php...
And this is to be expected, dynamic typing tends to make things go slow.

> But it is much faster in writing.
If you compare with old-fashioned languages like C, Java or Go, then certainly. If you compare to statically typed, functional languages (e. g. Scala), then no. A good static type system is a huge boon for maintenance, productivity and tooling, and so is functional programming. Python supports neither, which pretty much disqualifies it for serious projects as far as I'm concerned.

The moral dimension of performance

Posted Sep 17, 2017 12:55 UTC (Sun) by mathstuf (subscriber, #69389) [Link]

I agree about the productivity thing. Usually I have my inputs and know where the output is going, so I wire up or declare these first and then code up the middle. The compiler tells me where my code shape doesn't work which is much better than "looks like it worked" followed by debugging in dynamic languages.

Sets versus lists ...

Posted Aug 31, 2017 11:11 UTC (Thu) by Wol (guest, #4433) [Link]

> we want to define the order of the fields according to the order we give keyword arguments;
> we want to give keyword arguments in any order without caring about the field order.

> We can't have both, and we can't give up either without being a surprising source of annoyance and bugs.

This is exactly why I scream at relational databases. If you can't tell the difference between a set and a list, and especially if you want to store a list in a set-based paradigm, you are going to have ALL SORTS of grief ...

Cheers,
Wol


Copyright © 2017, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds