Mohamed Mabrouk
MModular
•Created by Ivo Balbaert on 1/7/2025 in #questions
Try finally when opening a file
the error would be in opening the file and initializing the file handle, in the case there are no resources to free.
13 replies
MModular
•Created by Ivo Balbaert on 1/7/2025 in #questions
Try finally when opening a file
the try block is scoped, so the initialization is only happening within this scope, otherwise
file
is still uninialized. you can move the close statement to the try block instead.13 replies
MModular
•Created by duck_tape on 1/3/2025 in #community-showcase
A Benchmark with Files and Bytes
Here are the corresponding results on intel.
24 replies
MModular
•Created by duck_tape on 1/3/2025 in #community-showcase
A Benchmark with Files and Bytes
yes, I used the latest extramojo, and used the script in the records directory.
I can't say if it's rust or the memchr package specifically that they are using subpar algorithm for Arm.
based on my previous experiments, I can match the performance or memchr on x86 by careful optimization, removing unnecessary function calls and allocations, and optimizing the buffer size. I can try to see if using the rolled-up buffered reader that I have can make a difference.
24 replies
MModular
•Created by duck_tape on 1/3/2025 in #community-showcase
A Benchmark with Files and Bytes
Here the hyperfine results after fixing a small import bug in the rust script
Rust 1.83, Mojo 26.6.
as expected the rust implementation is more performant on Intel-X86 than on ARM-Mac and now beats mojo.
24 replies
MModular
•Created by duck_tape on 1/3/2025 in #community-showcase
A Benchmark with Files and Bytes
I can give the code a try on an Intel machine, and I can report the results here
24 replies
MModular
•Created by duck_tape on 1/3/2025 in #community-showcase
A Benchmark with Files and Bytes
the memchr crate uses SIMD already and goes to great length to provide vectorized arch-specific implementations. I am not sure if there is a better solution in the rust ecosystem.
24 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
I will probably keep experimenting for a bit to see how this would work. one obvious advantage is that the lifetime of the references to the mapped file would be valid as long as the file is still mapped, that would simplify multi-threads that can be in different stages of a multi-step pipeline
68 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
it's user-specific most people won't use 50G files on windows, I am just cloning a cross-platform industry standard tool in the field to Mojo and I want to have a good cross-platform sequential IO as the first step, I would like to ideally support multi threading at somepoint and the mmap is much more ergonomic than buffered reader on linux but it seems less predictable and portable on Mac and Windows
68 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
would the huge page config differ between MAC and Linux or it's POSIX thing? also how portable would this setup be to windows?
68 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
that would be great, the cost of page faults becomes non-trivial with increasing file size.
68 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
in my experiments, I am doing zero-copy buffered line iterator at around 5G/s from NVME disk, I will play around with mmap to see how it would work and if I can extract a bit more performance from this strategy (at least avoiding the syscall overhead).
68 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
It would be great if you can pass around some example code, I tried this in early mojo (b4 0.6) and I would like to circle back to it again now
68 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
I got so many segfaults when I tried to use mmap API through early mojo ffi that kept me away 😅
68 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
In general, I think the buffered IO is a nice interface to have in addition to the more fancy IO strategies, coming from other langs and domains, this one of the tools that you intuitively reach for in the beginning.
68 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
I think for some use cases reading the whole file at once would not work, I work regularly with file sizes of 10s-100s GB per file, and it may not be feasible for most systems to even have memory of this size. mmap could be used in this case, but I haven't tried it yet. Also in my early experiments I found that doing buffered IO and parsing with a smaller buffer (64 KB) is as efficient or even slightly more efficient than reading the whole file at once (at least on my hardware) for file sizes around 1GB.
For the zero-copy iterator, I currently have a version which returns byte spans instead for doing additional memory allocation, this minimizes the memalloc overhead at least. the main problem with this approach is the associated lifetime of the span and who it should be invalidated upon the buffer refill.
68 replies
MModular
•Created by duck_tape on 12/10/2024 in #community-showcase
ExtraMojo
It is nice that you found the buffered line reader useful. I originally hand-rolled it for my needs and I made several modification in it over the time, it is also not straightforward implementation as it returns tesnor of bytes and not strings (it was started in the pre-list era). I was planning on splitting a more complicated version of the buffered reader (and a companion buffered writer) as it's own package, if you are interested in the buffered IO part, we can work on a more pythonic implementation, which if useful can find its way eventually to stdlib (python do buffered reads by default in some cases).
68 replies
MModular
•Created by jmky on 10/7/2024 in #questions
Is there a disdain for Rust from the Mojo team?
Early on, Mojo adapted the
&
convention for immutable references which was later renamed to borrowed
. I think the main idea in Mojo syntax is ensuring clarity of syntax on the expanse of line space. so &
and other signs does not really fit in the current Mojo syntax. Conceptually, Mojo explicitly follows Rust's lead in exclusivity checking and lifetime tracking.23 replies
MModular
•Created by cirqol on 9/8/2024 in #questions
Just learn Mojo?
It will be depending on the level that you are writing your package, for low-level mojo which involves memory management and playing around with pointers, python is not really useful here and emulating Rust or C code is more useful here, porting them to Mojo is in many cases easier to porting python.
If you want to port python code to mojo, then it is helpful to know python, but then only a small subset of python code that can be ported right now.
4 replies