Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotating dash generates way too much output #3859

Closed
mc-butler opened this issue Sep 24, 2017 · 12 comments
Closed

Rotating dash generates way too much output #3859

mc-butler opened this issue Sep 24, 2017 · 12 comments
Assignees
Labels
area: core Issues not related to a specific subsystem prio: medium Has the potential to affect progress
Milestone

Comments

@mc-butler
Copy link

Important

This issue was migrated from Trac:

Origin https://midnight-commander.org/ticket/3859
Reporter egmont (@egmontkob)

I have a directory containing 2 million files. Using script I recorded starting up mc (takes about 10 seconds) and then quitting immediately.

Without rotating dash, the resulting typescript file is around 4 kB. With rotating dash, it's about 2 MB. (This is with the default skin; with 256-color or 16M-color skins it's even more.)

mc shouldn't generate megabytes of traffic for such an eye candy. It might even cause severe usability problems over a slow network.

It's one thing that it keeps setting the foreground and background colors which could be optimized away, but it's probably not the right direction to start.

On another note, IMO the rotating dash doesn't look too nice. It spins crazily too fast.

What I have in mind:

Currently layout.c's rotate_dash() keeps the last state in a static variable, bumps it each time and draws the new shape.

Instead, the shape to be drawn should be taken from g_get_monotonic_time(), scaled to a few steps per second, modulo the number of phases to draw. Plus, the last drawn shape should be stored in a static variable and the new one only actually painted if it has changed.

This would result in a nicer look (spinning with a reasonable constant speed) and save significantly on the produced amount of data.

There are maybe one or two more places at the source where a rotating dash is presented, they should also be updated.

Let me know if you have any objection against this change. If not, I'll be happy to come up with a patch.

Note

Original attachments:

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Sep 27, 2017 at 21:42 UTC

Proposal

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Sep 27, 2017 at 21:48 UTC (comment 1)

Please see the attached patch. I was thinking of something like this.

Each time there was an "action", it only rotates the dash if at least 1/8 seconds have elapsed from the last time (or if the dash is initially drawn).

This arbitrarily made up constant corresponds to the theoretical upper limit of 1 complete rotation of the dash per second, which upper limit cannot be reached (would require rotate_dash() to be called again immediately once this amount of time elapses, plus rotate_dash() itself to execute immediately).

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Sep 28, 2017 at 5:28 UTC (comment 2)

I think we should use mc_time_elapsed() instead of g_get_monotonic_time().

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Sep 28, 2017 at 9:02 UTC (comment 2.3)

Replying to andrew_b:

I think we should use mc_time_elapsed() instead of g_get_monotonic_time().

mc requires glib >= 2.26, but g_get_monotonic_time is in glib >= 2.28.

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Sep 28, 2017 at 12:40 UTC (comment 3.4)

The version requirement is a nice catch, thanks! glib-2.28 is 6.5 years old, I wouldn't mind bumping the requirement.

lib/util.c's mc_time_elapsed() uses a global timer, and as such I'm not brave enough to use it here. Even if it happens to work, it's a fragile design and we can't tell when a subsequent refactoring will make it clash with another timer. As such, I'd rather fallback to manually using its underlying mc_timer_elapsed().

However, back to mc_time_elapsed() for a moment, this is what takes care of the only tricky thing here: clock skew. In other words, makes sure we won't get stuck in the "not yet elapsed" state for a loooong time on some rare circumstances. (My patch, even though theoretically not necessary with monotonic_time, takes care of it by using unsigned ints.)

The underlying mc_timer_{new,destroy,elapsed} seems to be much ado for nothing, a truly thin wrapper that would especially be pointless if we refactored to g_get_monotonic_time().

How about the following:

I'll refactor mc so that mc_time_elapsed doesn't have the global timer hardcoded, it gets it injected as a guint64*. I'll make it rely on monotonic clock. I might add another similar convenience method as needed, it'll turn out during the actual work. I'll remove the mc_timer_t stuff. (I don't know yet how it's exactly going to look like, this is just a rough direction.) And of course make the rotating dash rely on this/these method(s) too.

I'm fine if we don't make it into 4.8.20 but only 4.8.21, then glib-2.28 will already be 7 years old.

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Sep 28, 2017 at 13:52 UTC (comment 4.5)

Replying to egmont:

I'll remove the mc_timer_t stuff. (I don't know yet how it's exactly going to look like, this is just a rough direction.) And of course make the rotating dash rely on this/these method(s) too.

I have an idea to make gettimeofday(2) wrapper and simplify time compare in get_key_code(), learcn_key() and some other places and get rid of gettimeofday(2) calls at all. mc_timer_t was the first step. Other steps are partially implemented, but branch is not published and too old.

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Sep 28, 2017 at 14:19 UTC (comment 6)

If we can use g_get_real_time() and g_get_monotonic_time(), which I believe we can without any worries, then I believe introducing another layer and data type (let alone the mallocs and frees) no longer makes too much sense. (It made sense of course on top of the really inconvenient gettimeofday().) Would you be up for going with these two methods and gint64 as the data type instead of mc_timer_t, and writing convenience methods on top of these?

If you insist on mc_timer_t then of course I'll rewrite my patch to go on top of that.

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Oct 1, 2017 at 4:24 UTC (comment 6.7)

Replying to egmont:

Would you be up for going with these two methods and gint64 as the data type instead of mc_timer_t, and writing convenience methods on top of these?

Ok.

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Sep 8, 2019 at 9:23 UTC (comment 8)

  • Owner set to andrew_b
  • Milestone changed from Future Releases to 4.8.24
  • Branch state changed from no branch to on review
  • Status changed from new to accepted

Branch: 3859_rotate_dash_rate
[9eb2b3991ef1528fb34be665794efc3b2fcdefdb]

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Sep 22, 2019 at 10:00 UTC (comment 9)

  • Votes set to andrew_b
  • Branch state changed from on review to approved

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Sep 22, 2019 at 10:01 UTC (comment 10)

  • Resolution set to fixed
  • Votes changed from andrew_b to committed-master
  • Status changed from accepted to testing
  • Branch state changed from approved to merged

Merged to master: [3195dd7].

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Sep 22, 2019 at 10:02 UTC (comment 11)

  • Status changed from testing to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues not related to a specific subsystem prio: medium Has the potential to affect progress
Development

No branches or pull requests

2 participants