[PATCH] Stop doing the (very expensive) pow() calculation pointlessly

Linus Torvalds torvalds at linux-foundation.org
Sun Jan 19 13:03:30 UTC 2014


On Sun, Jan 19, 2014 at 12:42 PM, Tomaz Canabrava <tcanabrava at kde.org> wrote:
> The result of this patch is this:
> http://wstaw.org/m/2014/01/19/plasma-desktopujz493.png
> it still looks like it deserves some kind of special treatment, but it's way
> faster now.

So you seem to have TTS enabled (time-to-surface).

What do you use as a test-case? Because there are a few tests in there
that generate horrible TTS loads because they are actually bad dives
with tons of deco, and then the TTS calculations just explode.

Anyway, for the TTS calculations, try this trivial patch that makes
the TTS code use a 1-minute step-size rather than calculate things at
a 10s interval.

There are other things we could do too. For example, in
calculate_deco_information() we actually do the deco calculations by
adding a segment for every *second* (see the loop that goes like

                for (j = t0+1; j <= t1; j++) {
                        int depth = interpolate(entry[-1].depth,
entry[0].depth, j - t0, t1 - t0);
                        double min_pressure =
add_segment(depth_to_mbar(depth, dive) / 1000.0,

&dive->cylinder[entry->cylinderindex].gasmix, 1, entry->po2 * 1000,
dive);
                        tissue_tolerance = min_pressure;
                }

and that whole loop is likely pointless. We could just do that one
plot-entry at a time (we do plot entries generally at a minumum of
10-second intervals, depending on sample intervals etc they can be
more common).

The second patch has that "simplify calculate_deco_information" part
in it too (in *addition* to the 60s TTS interval change that is in the
first one).

I bet the first one is the one that makes more of a difference, but
you can try to see if the second patch improves things further.

               Linus
-------------- next part --------------
 profile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/profile.c b/profile.c
index 45c0c83a346a..1c212f8f070e 100644
--- a/profile.c
+++ b/profile.c
@@ -1088,7 +1088,7 @@ static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry,
 	const int ascent_s_per_deco_step = 1;
 	const int ascent_mm_per_deco_step = 16; /* 1 m/min */
 	/* how long time steps in deco calculations? */
-	const int time_stepsize = 10;
+	const int time_stepsize = 60;
 	const int deco_stepsize = 3000;
 	/* at what depth is the current deco-step? */
 	int next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance, surface_pressure, dive, 1), deco_stepsize);
-------------- next part --------------
 profile.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/profile.c b/profile.c
index 45c0c83a346a..3e35e762f35e 100644
--- a/profile.c
+++ b/profile.c
@@ -1088,7 +1088,7 @@ static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry,
 	const int ascent_s_per_deco_step = 1;
 	const int ascent_mm_per_deco_step = 16; /* 1 m/min */
 	/* how long time steps in deco calculations? */
-	const int time_stepsize = 10;
+	const int time_stepsize = 60;
 	const int deco_stepsize = 3000;
 	/* at what depth is the current deco-step? */
 	int next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance, surface_pressure, dive, 1), deco_stepsize);
@@ -1162,16 +1162,15 @@ static void calculate_deco_information(struct dive *dive, struct divecomputer *d
 	for (i = 1; i < pi->nr; i++) {
 		struct plot_data *entry = pi->entry + i;
 		int j, t0 = (entry - 1)->sec, t1 = entry->sec;
-		for (j = t0+1; j <= t1; j++) {
-			int depth = interpolate(entry[-1].depth, entry[0].depth, j - t0, t1 - t0);
-			double min_pressure = add_segment(depth_to_mbar(depth, dive) / 1000.0,
-					&dive->cylinder[entry->cylinderindex].gasmix, 1, entry->po2 * 1000, dive);
-			tissue_tolerance = min_pressure;
-		}
-		if (t0 == t1)
+
+		if (t0 == t1) {
 			entry->ceiling = (entry - 1)->ceiling;
-		else
-			entry->ceiling = deco_allowed_depth(tissue_tolerance, surface_pressure, dive, !prefs.calc_ceiling_3m_incr);
+			continue;
+		}
+		tissue_tolerance = add_segment(depth_to_mbar(entry->depth, dive) / 1000.0,
+				&dive->cylinder[entry->cylinderindex].gasmix, t1-t0, entry->po2 * 1000, dive);
+		entry->ceiling = deco_allowed_depth(tissue_tolerance, surface_pressure, dive, !prefs.calc_ceiling_3m_incr);
+
 		for (j=0; j<16; j++)
 			entry->ceilings[j] = deco_allowed_depth(tolerated_by_tissue[j], surface_pressure, dive, 1);
 


More information about the subsurface mailing list