ProcessIEnumerableRecursively

Topics: Developer Forum
Coordinator
Dec 26, 2006 at 10:30 PM
Beware that this can be a good bit slower especially when dealing with large collections. I would prefer to process the whole collection in some cases e.g. _byteInput.AddRange(byteArray).
Developer
Dec 26, 2006 at 11:01 PM
added
RegisterInputType<IEnumerable<byte>>(delegate(IEnumerable<byte> bytes)
{
    _byteInput.AddRange(bytes);
});
Developer
Dec 26, 2006 at 11:27 PM
but still we have no guarantee this will be called instead of the IEnumerable, since we depend on type.GetInterfaces(), which returns them in no particular order.

i could hardcode the IEnumerable handler after the interface lookup...
Developer
Dec 27, 2006 at 4:11 AM
so, IEnumerable is hardcoded as the last chance handler. but we are still getting the bytes one by one from powershell, when the pipeline syntax is used...
Coordinator
Dec 27, 2006 at 4:39 AM
Yeah this was weird in that the byte[] comes in as inputObject.BaseObject equal to object[]. I had to get the object elements and try to convert them to byte and error out if one of elements wasn't a byte. Not sure if that is any help or not but that's what I recall about it.
Developer
Dec 27, 2006 at 4:53 AM
hmm, i am not sure whether we're talking about the same issue here. the problem is not the array coming as an object[], but the ProcessRecord() being called for each byte in the pipeline case:

[10] » $random = new random
[11] » $buff = new byte[] 50KB
[12] » $random.NextBytes($buff)
[13] »
[13] » Measure-Command { Get-Hash -in $buff }
 
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 328
Ticks             : 3285087
TotalDays         : 3,80218402777778E-06
TotalHours        : 9,12524166666667E-05
TotalMinutes      : 0,005475145
TotalSeconds      : 0,3285087
TotalMilliseconds : 328,5087
 
[14] » Measure-Command { $buff | get-hash }
 
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 6
Milliseconds      : 561
Ticks             : 65618926
TotalDays         : 7,59478310185185E-05
TotalHours        : 0,00182274794444444
TotalMinutes      : 0,109364876666667
TotalSeconds      : 6,5618926
TotalMilliseconds : 6561,8926
 
[15] »
Coordinator
Dec 27, 2006 at 5:04 AM
I think we are talking about the same thing. What I'm saying is that I had coded this to handle ProcessRecord objects that were byte[] (well object[] really). Check out the 10x perf diff here:

19> $arr = gc foo.dll -enc byte
20> measure-command { $arr | get-hash }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 31
Ticks : 316801
TotalDays : 3.66667824074074E-07
TotalHours : 8.80002777777778E-06
TotalMinutes : 0.000528001666666667
TotalSeconds : 0.0316801
TotalMilliseconds : 31.6801

21> measure-command { ,$arr | get-hash }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 3
Ticks : 35126
TotalDays : 4.06550925925926E-08
TotalHours : 9.75722222222222E-07
TotalMinutes : 5.85433333333333E-05
TotalSeconds : 0.0035126
TotalMilliseconds : 3.5126
Developer
Dec 27, 2006 at 5:17 AM
oh, we are talking about the same thing :) the question is, how to force powershell to pass us the byte array (in an object array, or just as-is, or whatever else but single bytes). but i am afraid that is not possible :/
Coordinator
Dec 27, 2006 at 5:21 AM
Yeah it is up to the end user to prevent the pipeline from shredding the byte[] by wrapping that array inside another array using the comma operator. That said, it appears to work as expected using the current PscxInputObjectPathCommandBase so I'm good for now.
Developer
Dec 27, 2006 at 5:48 AM
hm, we should mention in help, that there are at least three possibilities how to pass the array, and the most intuitive one being also the worst one :)
Coordinator
Dec 27, 2006 at 6:22 AM
Yes that would make a good Note/Remark. What is the state of the help stuff? Is there a place to create this file or does it already exist?
Developer
Dec 27, 2006 at 9:50 PM
PS> $b = byte[] (65,66,67,68,69)

PS> $b | % -processp : $_

p : 65
p : 66
p : 67
p : 68
p : 69

PS> "$b" | % -processp : $_

p: 65 66 67 68 69

That seems a bit cleaner over a leading comma, no?

- Oisin
Developer
Dec 27, 2006 at 9:51 PM
hmm, my curly braces disappeared. testing. { \{
Developer
Dec 27, 2006 at 10:33 PM
ok, never mind my ridiculous suggestion -- wrapping it in quotes just sends a string, not a byte[] of course.

runs back into bed
Coordinator
Dec 28, 2006 at 4:36 AM
See this link for the Wiki markeup guide, apparently these formatting rules work in the forums also.

http://www.codeplex.com/CodePlex/Wiki/View.aspx?title=Wiki%20Formatting

 
"$b" | % -process { "p : $_" }

That "should" work. It would be nice if this forum software allowed you to preview your post before posting it.