[issue955] move struct.Struct to interplevel

New submission from Alex Gaynor <alex.gaynor@gmail.com>: There are a few reasons and issues to be fixed: 1) format should be immutable on the Struct instance 2) format should be promoted so that unpack/pack loops are unrolled correctly 3) it should work nicer with buffers Discussion from IRC: [6:24 PM] <Alex_Gaynor> arigato: so struct.unpack is very fast because the JIT checks if the format str is constant and if it is unrolsl the loops [6:24 PM] <arigato> ah, bah [6:24 PM] <Alex_Gaynor> arigato: however if you have x = Struct("format str"); for i n xrange(100): x.unpack(i) or so, the string isn't constant [6:24 PM] <Alex_Gaynor> it'd be ok if Struct was a global or something [6:24 PM] <Alex_Gaynor> I would if Struct instances should just promote their format and be done with it [6:24 PM] <arigato> and even not, because x.format is not a constant attribute [6:25 PM] <Alex_Gaynor> is it constant on CPython? [6:25 PM] <arigato> I suppose, but right now it's written at app-level [6:25 PM] <arigato> in pypy [6:25 PM] ⇐ lucian (~lucian@cpc1-newc15-2-0- cust84.gate.cable.virginmedia.com) quit: Ping timeout: 240 seconds [6:25 PM] <Alex_Gaynor> arigato: yes, I guess it might make sense to move it to interplevel so we can make it const and do the promotion [6:25 PM] <Alex_Gaynor> I think promote makes sense here [6:25 PM] <arigato> yes and no, as usual [6:26 PM] <Alex_Gaynor> indeed [6:26 PM] <arigato> e.g. what if someone does x = Struct("i" * n) [6:27 PM] <arigato> well I suppose that he's punished and it's his fault, or something [6:27 PM] <Alex_Gaynor> indeed, as always the mess of heuristics :/ [6:27 PM] <arigato> yes [6:27 PM] <exarkun> I did that this afternoon. [6:27 PM] <arigato> ah no, it's potentially a bad idea to promote a string, anyway [6:27 PM] ⇐ JaRoel|4d (~jaroel|4d@2001:980:7133:1:317d:e87f:5636:fdbe) quit: Remote host closed the connection [6:28 PM] <arigato> I think it's promoting the pointer, not the actual string content [6:28 PM] <Alex_Gaynor> arigato: err, yes, we have string_promote nowadays though [6:28 PM] <arigato> ah, ok Benchmark: http://pastebin.com/brfj0Aq9 ---------- messages: 3546 nosy: agaynor, pypy-issue priority: performance bug status: unread title: move struct.Struct to interplevel ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue955> ________________________________________

Brian Kearns <bdkearns@gmail.com> added the comment: Some of these issues were fixed a while ago, rest should be fixed with commits 0928de0 through d93da94. ---------- nosy: +bdk status: unread -> testing ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue955> ________________________________________

Brian Kearns <bdkearns@gmail.com> added the comment: Actually, there are is a remaining inefficiency in pack_into: PackFormatIterator always packs into a string and then copies into the buffer. It should be possible to pack into the buffer directly. Seems solving this requires modification of both pypy/module/struct and rpython/rlib/rstruct. ---------- status: testing -> chatting title: move struct.Struct to interplevel -> inefficiency of struct.pack_into ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue955> ________________________________________
participants (2)
-
Alex Gaynor
-
Brian Kearns