
Create mixed reality models in PowerShell - cosmosdarwin
http://www.cosmosdarwin.com/2018/01/12/create-mixed-reality-models-in-powershell.html
======
oelmekki
Cool tech. If anything, it shows that windows MR tools are mature enough to be
used in most languages... on Windows.

I know one can work on projects that target Hololens using only Unity3D, but
it doesn't help much since the SDK needed to build them are only available on
Windows.

Given the "recent" interest for Linux at Microsoft and their mea culpa
regarding Internet Explorer, I would have hoped they made their Hololens SDK
crossplatform. Platform lock-in worked well for iOS, but then again, I wonder
if Android would have had so much success if it hadn't the only crossplatform
mobile SDK (I wonder if I'm not mistaken, here: did Blackberry have a
crossplatform SDK?).

Anyway, it's cool to see them going forward. Best of luck.

------
throwaway7645
This is pretty impressive. Powershell has been pretty slow for a lot of my
uses lately. The author said this took ~30 secs. How long would a similar
script take in Python? They're both slow on the language performance spectrum,
but I bet Python would be significantly faster if anyone is less lazy than me
to actually write some code.

~~~
da_chicken
PowerShell is slow, but writing to files the way he is doing is just a bad
pattern. He uses Add-Content not just in loops, but in _nested_ loops. The
problem with that is that each time Add-Content is called the system opens the
file, adds the content, flushes to disk, and then closes the file. That's a
_lot_ of overhead.

In his wine glass script he also uses the PowerShell patten of creating an
array ($x = @()) and then appending to it (foreach ($i in $set) { $x += $value
* $i }). The problem here is that PowerShell arrays are fixed in size. To
append a value to an array, the system creates a new array, copies all the
values over with the new one, and then disposes of the old array. It works
fine up to about 100 items, but it gets noticeably slow after that. Since it's
done with a loop it makes it somewhere between O(n log n) and O(n^2). It's
better to just output all the values as a single array ($x = $set | ForEach {
$value * $_ }) or to create an ArrayList or List<String> or _some_ C#
collection that supports an O(1) append.

He also assigns a lot of variables in his loops and then uses them only once
to format a string. He could eliminate those variables and just embed the
expressions in the strings.

I got a ~25% performance improvement (210 ms to under 140 ms) with just the
script embedded in the article when I switched to StringBuilder instead of
Add-Content, and that script doesn't have the poor array pattern. StreamWriter
would work, too, with less memory pressure than a StringBuilder. I suspect
that with better code you could easily get this down below 3 seconds.

~~~
lburton
I got a lot more than a 25% improvement.. you seem to have a much quicker
machine or perhaps you were running one of the earlier scripts? For the wine
glass script it went from >2 minutes to 1.5 seconds when output buffered.
[https://github.com/cosmosdarwin/obj-in-
powershell/pull/1](https://github.com/cosmosdarwin/obj-in-powershell/pull/1)

Also for those that haven't come across it
[https://github.com/dlwyatt/PowershellProfiler](https://github.com/dlwyatt/PowershellProfiler)
is pretty useful.. despite add-content being the obvious offender here..

~~~
da_chicken
I have a 10 year old PC. The 210ms to 140 ms time was with the single cylinder
script, which is much shorter, and the < 3 second prediction was for the wine
glass script. I just guessed by looking that it wouldn't be hard to improve by
an order of magnitude. Sorry if I wasn't clear!

------
dingo_bat
I never knew mixed reality viewer was so awesome!

------
wodenokoto
Who's Jeffrey and why should he be proud?

~~~
ygra
Jeffrey Snover, creator of PowerShell, I guess.

------
k_sze
The real lesson here is to make sure you have a real programming language
development environment on any laptop you bring with you.

I’m only kidding, of course.

This post is actually quite cool.

~~~
Udik
> make sure you have a real programming language development environment on
> any laptop you bring with you

Or just write Javascript and execute it on your browser.

------
Udik
> What apps do I have? Aha! PowerShell.

Yep. And a browser that will execute any javascript at breakneck speed.

------
oblio
This should be unflagged, IMO.

~~~
darklajid
I agree.

There's a vouch link for bad comments. Is there something similar for stories?
Can a number of people "unflag" this?

~~~
oblio
If there is, I don't see it :(

~~~
mschuster91
Me neither, despite >6k points... @dang, is there a way "vouch" can be
implemented for ordinary users?

~~~
2510c39011c5
well, how to define “ordinary user” is a huge problem for the system
administrator — access control is at the root of all security issues...

~~~
mschuster91
In HN speak, another karma threshold (downvoting ~500 points, flagging ~1k
points if I'm not mistaken). ;)

~~~
2510c39011c5
it is all about different labels...and different labels have different
visibility, in terms of effort to get to that information...so I guess by
narrowing unflagging privilege to a very small group of users, the mod hopes
to make it significantly more difficult for people to advocate a certain post
here through purposeful manipulation...thus perhaps “unflagging” capability,
as one of the last lines of defense, is only given to a very small group of
ultimately verified users, through manual assignment or some thrshold based on
percentage rather than an absolute karma value...

that’s my guess...

