A command-line power tool for Twitter
github.com
github.com
I wish Twitter, Inc weren't the absolutely stinking worst maker of Twitter clients. :(
That's not what threads are about.
I see what you're saying here, but given that t had little other choice, I don't see how this comment adds any value other than to attempt to point out anything that could possibly be wrong with t.
Instead, I think t is fantastic. The usage of threads is good enough, and I thank Erik for spending so much time on a sweet little utility.
On my laptop, thread creation (pthread_create() followed by pthread_detach() takes ~17 microseconds.
When one end of a socket is on the Internet somewhere, connection time is ~80ms. If I start a thread and then have it create a network connection, eliminating the therad spawn overhead couldn't save more than 0.02% (that's two percent of a percent) of the running time, by Amdahl's law.
The effect of thread creation just isn't significant here. If this utility is going to spawn 1,000 simultaneous API connections to twitter, the threads could all be started by the time the first connection succeeds.
(My numbers come from a class assignment where I benchmarked some unrelated stuff, but if you're interested, I can send you the report)
If you would spin up threads just for this you're wasting memory and slowing down startup time.
And if you would destroy the threads and spin them up again for every batch of API calls, the result may counterintuitively be a slower app due to the overhead of creating the threads themselves.
At the same time concurrency is free. There's no overhead for doing a call async.