Saturday, December 3, 2016

Optimization and Performance

Some good thoughts here: http://joeduffyblog.com/2010/09/06/the-premature-optimization-is-evil-myth/

I am personally used to writing code where 100 CPU cycles matters. So invoking a function that acquires a lock by way of a shared-memory interlocked instruction that may take 100 cycles is something I am apt to think hard about; even more worrisome is if that acquisition could block waiting for 100,000 cycles. Indeed this situation could become disastrous under load. As you can tell, I write a lot of systems code. If you're working on a network-intensive application, on the other hand, most of the code you write is going to be impervious to 100 cycle blips, and more sensitive to efficient network utilization, scalability, and end-to-end performance. And if you're writing a little one-time script, or some testing or debugging program, you may get away with ignoring performance altogether, even multi-million cycle network round-trips.

To be successful at this, you'll need to know what things cost. If you don't know what things cost, you're just flailing in the dark, hoping to get lucky. This includes rule of thumb order of magnitudes for primitive operations – e.g. reading / writing a register (nanoseconds, single-digit cycles), a cache hit (nanoseconds, tens of cycles), a cache miss to main memory (nanoseconds, hundreds of cycles), a disk access including page faults (micro- or milliseconds, millions of cycles), and a network roundtrip (milliseconds or seconds, many millions of cycles) – in addition to peering beneath opaque abstractions provided by other programmers, to understand their best, average, and worst case performance.

Clearly the concerns and situations you must work to avoid change quite substantially depending on the class of code you are writing, and whether the main function of your program is delivering a user experience (where usability reigns supreme), delivering server-side throughput, etc. Thinking this through is crucial, because it helps avoid true "premature optimization" traps where a programmer ends up writing complicated and convoluted code to save 10 cycles, when he or she really needs to be thinking about architecting the interaction with the network more thoughtfully to asynchronously overlap round-trips. Understanding how performance impacts the main function of your program drives all else.


--
If I esteem mankind to be in error, shall I bear them down? No. I will lift them up, and in their own way too, if I cannot persuade them my way is better; and I will not seek to compel any man to believe as I do, only by the force of reasoning, for truth will cut its own way.

"Thou shalt love thy wife with all thy heart, and shalt cleave unto her and none else."

Sunday, November 13, 2016

Clemency abuse

https://www.warhistoryonline.com/featured/bloodiest-medieval-war-fought-bucket.html

Here's one way to abuse clemency. 'To make his edict stick, the pope offered indulgences to anyone who successfully attacked Bonacolsi and/or his property. Indulgences were a guarantee that sins were either forgiven or lightened to the extent that one didn't have to burn in hell. Not even for the sin of murder.'

Tom Kratman, no dummy he, has previously observed in one of his SF novels (Caliphate, IIRC) that an (evil, psychotic, awful) President could use the Presidential pardoning power in just such a way. Spoiler alert: that Presidency doesn't turn out well for the U.S., but it turns out even worse for Iran.

--
If I esteem mankind to be in error, shall I bear them down? No. I will lift them up, and in their own way too, if I cannot persuade them my way is better; and I will not seek to compel any man to believe as I do, only by the force of reasoning, for truth will cut its own way.

"Thou shalt love thy wife with all thy heart, and shalt cleave unto her and none else."

Wednesday, November 2, 2016

Kipling

I love Kipling.


As I pass through my incarnations
In every age and race,
I make my proper prostrations
To the Gods of the Market Place.
Peering through reverent fingers
I watch them flourish and fall,
And the Gods of the Copybook Headings,
I notice, outlast them all.

We were living in trees when they met us.
They showed us each in turn
That Water would certainly wet us,
As Fire would certainly burn:
But we found them lacking in Uplift,
Vision and Breadth of Mind,
So we left them to teach the Gorillas
While we followed the March of Mankind.

We moved as the Spirit listed.
They never altered their pace,
Being neither cloud nor wind-borne
Like the Gods of the Market Place,
But they always caught up with our progress,
And presently word would come
That a tribe had been wiped off its icefield,
Or the lights had gone out in Rome.

With the Hopes that our World is built on
They were utterly out of touch,
They denied that the Moon was Stilton;
They denied she was even Dutch;
They denied that Wishes were Horses;
They denied that a Pig had Wings;
So we worshipped the Gods of the Market
Who promised these beautiful things.

When the Cambrian measures were forming,
They promised perpetual peace.
They swore, if we gave them our weapons,
That the wars of the tribes would cease.
But when we disarmed They sold us
And delivered us bound to our foe,
And the Gods of the Copybook Headings said:
"Stick to the Devil you know."

On the first Feminian Sandstones
We were promised the Fuller Life
(Which started by loving our neighbour
And ended by loving his wife)
Till our women had no more children
And the men lost reason and faith,
And the Gods of the Copybook Headings said:
"The Wages of Sin is Death."

In the Carboniferous Epoch
We were promised abundance for all,
By robbing selected Peter
To pay for collective Paul;
But, though we had plenty of money,
There was nothing our money could buy,
And the Gods of the Copybook Headings said:
"If you don't work you die."

Then the Gods of the Market tumbled,
And their smooth-tongued wizards withdrew
And the hearts of the meanest were humbled
And began to believe it was true
That All is not Gold that Glitters,
And Two and Two make Four
And the Gods of the Copybook Headings
Limped up to explain it once more.

As it will be in the future,
It was at the birth of Man
There are only four things certain
Since Social Progress began.
That the Dog returns to his Vomit
And the Sow returns to her Mire,
And the burnt Fool's bandaged finger
Goes wabbling back to the Fire;

And that after this is accomplished,
And the brave new world begins
When all men are paid for existing
And no man must pay for his sins,
As surely as Water will wet us,
As surely as Fire will burn,
The Gods of the Copybook Headings
With terror and slaughter return!

--
If I esteem mankind to be in error, shall I bear them down? No. I will lift them up, and in their own way too, if I cannot persuade them my way is better; and I will not seek to compel any man to believe as I do, only by the force of reasoning, for truth will cut its own way.

"Thou shalt love thy wife with all thy heart, and shalt cleave unto her and none else."

Tuesday, October 25, 2016

5E slings

Good house rules for slings here: http://ludusludorum.com/2016/05/12/a-defense-of-the-humble-sling/

--
If I esteem mankind to be in error, shall I bear them down? No. I will lift them up, and in their own way too, if I cannot persuade them my way is better; and I will not seek to compel any man to believe as I do, only by the force of reasoning, for truth will cut its own way.

"Thou shalt love thy wife with all thy heart, and shalt cleave unto her and none else."

Tuesday, October 18, 2016

CO2 Into Ethanol

Argh. I'm not educated enough to know what the implications are for this process with "high Faradaic efficiency (63 % at −1.2 V vs RHE) and high selectivity (84 %) that operates in water and at ambient temperature and pressure".

On the one hand, I remember how thermal depolymerization (turkey guts into oil) didn't pan out. On the other hand, I remember that one reason WHY it didn't pan out was that it turned out to be more expensive than anticipated to get the turkey guts--they had hoped to get them for free, but it turns out that normally turkey guts are sold for animal feed, and when the oil-makers had to pay for it, that cut into their profit margins. Plus, they had some early problems with odor that gave them PR issues. Neither of these would be expected to be an issue with ethanol-from-CO2, although I imagine that producing sufficient concentrations of CO2 to make the process work could be an engineering challenge. Also, "ambient temperature and pressure" seems like a big deal to me and very good news.

Overall I'm cautiously optimistic. Using nuclear power to turn CO2 into ethanol seems like a win-win-win scenario--although you'd obviously have to compare it to the competing scenario of using nuclear power to turn water into hydrogen for fuel cells, since both scenarios are really just ways of distributing energy. But I assume the PR for CO2-into-ethanol would be much better, which could make things politically easier.

I don't think this is a silver bullet. I doubt that more than 20% of the world's auto fuel will be produced via this method even twenty years from now--I expect we'll still be pumping most of our fuel out of the ground. But it will be great if this is a mature technology at that point which is proven to work reliably and economically.

Pop-sci article: http://www.popularmechanics.com/science/green-tech/a23417/convert-co2-into-ethanol/ 
Link to actual paper: http://onlinelibrary.wiley.com/doi/10.1002/slct.201601169/full

-Max

--
If I esteem mankind to be in error, shall I bear them down? No. I will lift them up, and in their own way too, if I cannot persuade them my way is better; and I will not seek to compel any man to believe as I do, only by the force of reasoning, for truth will cut its own way.

"Thou shalt love thy wife with all thy heart, and shalt cleave unto her and none else."