Le vendredi 11 septembre 2015 à 14:10 -0700, Corey Moncure a écrit : > https://github.com/cmoncure/crypto/blob/master/aes.jl > > In the process of learning Julia (and crypto) I implemented the > Rijndael block cipher and inverse cipher. I tried to write idiomatic > yet concise code, but the performance is not very desirable. On my > machine (i5-2500k @ 4.0 Ghz) the throughput is piddling, on the order > of 10e6 bytes/sec, and memory allocation is at 3056 bytes / block, > which I have not been able to cut down any further. > > Obviously I do not intend to compete with hand-tuned assembler > routines that heavily exploit SIMD and pre-computed tables, but my > completely unfounded gut feeling is that given the right input, Julia > should be able to approach within a factor of 4-10 without such > optimizations. Currently this routine is within a factor of 1000. > > Any Julia experts out there willing to take a peek at the code and > offer some tips for idiomatic (i.e. within the framework of Julia > syntax and style) optimizations? I haven't looked too deeply, but you shouldn't need most (if not all) type annotations for local variables. In particular, the ::Unsigned annotations have no effect at all, as Unsigned is an abstract type, and performance gains only happen when an annotation allows Julia to know the concrete type of a variable. Also, x = 0x0 automatically gives you a UInt8, no need to add an annotation; write 0x00 for a UInt16.
If you have doubts, you can call @code_warntype myfunction(x, y). That's 0.4 only IIRC, but now is a good time to switch to 0.4.0-rc1. If you don't spot anything problematic (in red), then you should compare the hot spots with native code generated from C. You can use @code_native for that. > In the course of doing this I have run into several gripes with > Julia, particularly some of the built-in functions which are often > confusing or contradictory by virtue of the type declarations of > certain methods (or lack of needed ones). For instance, Julia does > not support negative indexing of arrays... so then why do so many > functions on arrays take only signed integer types for dimensions? > To the noobie it seems like an obvious choice to type data holding > the calculation of matrix dimensions or indices as unsigned integers, > given that the language does not support negative indexing. Yet this > fails unexpectedly in many built-ins such as sub(). This has been discussed several times on the list, including recently. You should be able to find the thread in the archives. Basically, in Julia, unsigned types are only used to represent bits, never numeric values. Regards
