Show HN: Samchika – A Java Library for Fast, Multithreaded File Processing

(github.com)

Comments

Calzifer 23 May 2025

        for(int i=0;i<10000; ++i){

            // do nothing just compute hash again and again.
            hash = str.hashCode();
        }
https://github.com/MayankPratap/Samchika/blob/ebf45acad1963d...

"do nothing" is correct, "again and again" not so much. Java caches the hash code for Strings and since the JIT knows that (at least in recent version[1]) it might even remove this loop entirely.

[1] https://news.ycombinator.com/item?id=43854337

mprataps 23 May 2025
Guys. I love you all. I did not expect such quality feedback.

I will try to incorporate most of your feedback. Your commments have given me much to learn.

This project was started to just learn more about multithreading in a practical way. I think I succeeded with that.

sieve 23 May 2025
A note on the name.

The nasal "m" takes on the form of the nasal in the row/class of the letter that follows it. As "ñ" is the nasal of the "c" class, the "m" becomes "ñ"

Writing Sanskrit terms using the roman script without using something like IAST/ISO-15919 is a pain in the neck. They are going to be mispronounced one way or the other. I try to get the ISO-15919 form and strip away everything that is not a-z.

So, सञ्चिका (sañcikā) = sancika

You probably want to keep the "ch," as the average English speaker is not going to remember that the "c" is the "ch" of "cheese" and not "see."

sidcool 23 May 2025
It would be even more amazing if it had tests. It's already pretty good.
sureglymop 23 May 2025
Perhaps I misunderstand something but doesn't reading from a file require a system call? And when there is a system call, the context switches? So wouldn't using multiple threads to read from a file mean that they can't really read in parallel anyway because they block each other when executing that system call?
VWWHFSfQ 23 May 2025
Am I wrong in thinking that this is duplicating lines in memory repeatedly when buffering lines into batches, and then submitting batches to threads? And then again when calling the line processor? Seems like it might be a memory hog
mprataps 24 May 2025
I have CONTRIBUTING.md with guidelines regarding Pull Requests if any of you would take out your precious time to make some changes in the library.
codetiger 23 May 2025
Do you have a benchmark comparison with other similar tools?
stopthe 24 May 2025
Does it handle line breaks inside quotes in CSV? Frankly, I don't think its possible to reliably process CSV in а multi-threaded manner.
gavinray 23 May 2025
Please don't do this.

Have the OS handle memory paging and buffering for you and then use Java's parallel algorithms to do concurrent processing.

Create a "MappedByteBuffer" and mmap the file into memory.

If the file is too large, use an "AsynchronousFileChannel" and asynchronously read + process segments of the buffer.

SillyUsername 23 May 2025
An ArrayList for huge numbers of add operations is not performant. LinkedList will see your list throughput performance at least double. There are other optimisations you can do but in a brief perusal this stood out like a sore thumb.