

Tell HN: Threads fast - pg

I just rewrote the code that generates the threads page to be faster.  It used to be slow the first time you called it after a restart because it had to load lot of items into memory.  Now items aren't loaded till the moment they're needed.  This also makes it possible to show an unlimited number of threads.
======
jrockway
Very nice. Slow threads were annoying me due to the proxy at work -- if a page
took too long to respond, it would just randomly show some other page from
news.yc that happened to be in the cache. (Yes, really. Now I know who else
reads HN at work, and what topcolors they have chosen. ;)

This was a problem, because it seems that after I wrote a post, I immediately
realized there was some error, and I needed to fix it. The page that loads
after you "add commment" was also affected by the cache bug, so I couldn't get
an edit link there. I would have to try "threads" a number of times, and
eventually, if I was lucky, I would get the edit link. Then I could fix my
post. Frustrating. (And not really HN's fault, FWIW.)

I haven't tried this through the proxy yet, but it seems massively faster from
home, which should make the work proxy happier. Thanks!

~~~
andrewcooke
i'm curious - which proxy software does that?

~~~
jrockway
No idea. It's probably very expensive, though.

(The goal of our IT department is to spend the most money implementing the
worst possible solutions. If it doesn't cost $5,000,000 per user per year,
we're not interested. Example: I have to type 3 passwords to connect to the
VPN!)

~~~
andrewcooke
Ha! Maybe I should try bidding for their work - sounds like a nice client to
have ;o)

------
cperciva
Threads aren't really fast. The fact that you have a shared VM space allows
you to avoid the cost of swapping page tables (and flushing any logically-
addressed cache) but you still have to store and restore the entire
architectural state, which can easily take a few hundred cycles on systems
with lots of registers. Co-routines are much faster, since they allow the
compiler to optimize away handling of state which it knows isn't important.

... oh wait, wrong type of threads.

~~~
jrockway
Incidentally, the only usable Perl threads are implemented on top of
coroutines:

<http://search.cpan.org/~mlehmann/Coro-5.22/Coro.pm>

Just don't read the rant about why call/cc is useless.

------
jws
I had stopped using _threads_ because I felt bad about the load I was
imposing, frequently running until a timeout failure. Now it is
indistinguishable from instantaneous.

~~~
blhack
> _I felt bad about the load I was imposing_

This is how you know you've got loyal users.

~~~
robryan
As a user of adwords I always feel bad clicking on an sponsored link in Google
knowing I'm not going to buy anything.

~~~
samratjp
Yet it's amazing how there is another end of the spectrum where people are
hired to cost their competitors. Just the other day, I learned that apparently
"Mesothelioma" is one of the more expensive AdWords that easily goes around
$40!

------
tptacek
Yes. Threads fast. Thank you.

------
asnyder
As my mathematician partner always say, it's not unlimited, but rather a very
very large amount. I've learned to stop saying unlimited or infinite around
him, unless I can prove it theoretically, else he'll go into this shpeel about
the finite number of atoms in the universe.

~~~
jrockway
Unlimited means that the system imposes no limit on the number of threads to
be displayed -- each page uses a constant amount of resources, so there is no
limit to how far back in your history you can go.

That is my reading, anyway.

~~~
asnyder
I agree, I'm sure that's how he meant it. However, I was just trying to be
humorous, this being hacker news I thought it was applicable. Clearly nobody
else appreciated it.

~~~
jrockway
You're thinking of Slashdot.

------
dood
Excellent, any chance the 'saved' page can get a little improvement also? At
the moment it often just times out for me.

~~~
pg
That's next on my list.

~~~
pg
Should work reasonably well now.

~~~
boundlessdreamz
It timed out the first time, then loaded fast the next time.

------
icey
HUGE difference for me, thanks!

Actually, everything seems faster, not just /threads

------
MikeCapone
Thank you, much appreciated!

------
axod
Awesome :) Looking much better from here. Thanks

------
oomkiller
Oh thank you, it was so slow, but its now zippy as can be!

------
ax0n
Crazy lightning fast! Much appreciated.

------
anigbrowl
Thank you Paul!

