Intersting Performance Tip

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Intersting Performance Tip

Patrick Casey

Just thought I'd share this one in case other folks run into the same
bottleneck I was. It might not be a situation that many people run into, but
it was frustrating enough for me that I thought I'd share the solution on
the off chance other people ran into it.

If you're generating *lots* of very similar directlinks, the cost associated
with building each link (about 1 ms per on my laptop) starts to add up.

        When, you may ask, would one ever produce enough near-identical
direct links so that 1 ms per link would matter? In grids with a large
number of rows with leading "edit" links to allow you to pick a row off the
grid to edit.

        To give a more concrete example, this particular block of code:

       parameters = new Object[] { EDIT, id, key };
        fEditLink = cycle.getEngine().getService(Tapestry.DIRECT_SERVICE)
                .getLink(cycle, this, parameters).getURL();

        Was eating up 70% of the total time I spend rendering a 1,000 row

        Fortunately, there is a pretty straightforward solution. Since all
1,000 rows have the exact same link but for the value of the "id" and "key"
parameters, we can just generate one url and then use a bit of string
manipulation for the other 999 entries.

        So if we swap in:

       if (fEditLink == null) {
                        parameters = new Object[] { EDIT, "IDIDID",
                        fEditLink =
                                .getLink(cycle, this, parameters).getURL();
        String url = fEditLink.replaceAll("IDIDID", id);
        url = url.replaceAll("KEYKEYKEY", key);

        We can get the same 1,000 links out with only 1 call to the
(expensive) direct service and our grids are rendering about 3X as fast
(with is always good).

        So the short version is, avoid making lots of repetitive calls to
the direct service in performance critical blocks of your code.

        --- Pat

To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]