Skip to content

Commit

Permalink
quicker TUI blanking when search restarts
Browse files Browse the repository at this point in the history
1. Blanking is not immediate, because it causes flickering. But the TUI screen update delay is too long when the search results come in slowly. This change fixes that.
2. continue TUI file queueing, but more slowly after a large number was queued (64K to half a million files), to indicate that more files are still searchable and are queued (while not overusing the CPU to do so)
  • Loading branch information
genivia-inc committed Nov 7, 2023
1 parent dae4179 commit d736d6f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
4 changes: 2 additions & 2 deletions man/ugrep.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH UGREP "1" "November 03, 2023" "ugrep 4.3.2" "User Commands"
.TH UGREP "1" "November 06, 2023" "ugrep 4.3.2" "User Commands"
.SH NAME
\fBugrep\fR, \fBug\fR -- file pattern searcher
.SH SYNOPSIS
Expand Down Expand Up @@ -791,7 +791,7 @@ file types can be (where \fB\-t\fRlist displays a detailed list):
`scala', `scheme', `shell', `Shell', `smalltalk', `sql', `svg',
`swift', `tcl', `tex', `text', `tiff', `Tiff', `tt',
`typescript', `verilog', `vhdl', `vim', `xml', `Xml', `yacc',
`yaml', 'zig'.
`yaml', `zig'.
.TP
\fB\-\-tabs\fR[=\fINUM\fR]
Set the tab size to NUM to expand tabs for option \fB\-k\fR. The value of
Expand Down
6 changes: 3 additions & 3 deletions src/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,10 @@ class Output {
mode_ |= FLUSH;
}

// flush if output is line buffered to flush each line
void check_flush()
// flush if output is line buffered to flush each line, unless we have to wait to acquire the output lock
inline void check_flush()
{
if (mode_ == FLUSH)
if (mode_ == FLUSH && (sync == NULL || sync->try_acquire(lock_)))
flush();
}

Expand Down
5 changes: 2 additions & 3 deletions src/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1522,11 +1522,10 @@ void Query::search()

select_ = -1;
select_all_ = false;
updated_ = false;
tick_ = 4;

draw();
status(true);

updated_ = false;
}

// display the status line
Expand Down
36 changes: 16 additions & 20 deletions src/ugrep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ After this, you may want to test ugrep and install it (optional):
# define MAX_JOBS 16
#endif

// limit the job queue size to wait to give the worker threads some slack
// default limit on the job queue size to wait for worker threads to finish more work
#ifndef DEFAULT_MAX_JOB_QUEUE_SIZE
# define DEFAULT_MAX_JOB_QUEUE_SIZE 8192
#endif
Expand Down Expand Up @@ -2172,17 +2172,6 @@ struct Grep {
queue_work.notify_one();
}

// try to add a job to the queue if the queue is not too large
bool try_enqueue(const char *pathname, uint16_t cost, size_t slot)
{
if (todo >= flag_max_queue)
return false;

enqueue(pathname, cost, slot);

return true;
}

// pop a job
void dequeue(Job& job)
{
Expand Down Expand Up @@ -4095,12 +4084,6 @@ struct GrepWorker : public Grep {
jobs.enqueue(pathname, cost, slot);
}

// submit a job to this worker
bool try_submit_job(const char *pathname, uint16_t cost, size_t slot)
{
return jobs.try_enqueue(pathname, cost, slot);
}

// receive a job for this worker, wait until one arrives
void next_job(Job& job)
{
Expand Down Expand Up @@ -4184,12 +4167,25 @@ void GrepMaster::submit(const char *pathname, uint16_t cost)
iworker = min_worker;
}

// try to submit, if not successful then the queue reached max specified size
#ifdef WITH_LOCK_FREE_JOB_QUEUE

if (iworker->try_submit_job(pathname, cost, sync.next) || out.eof || out.cancelled())
break;

// give the worker threads some slack to make progress, then try again
std::this_thread::sleep_for(std::chrono::milliseconds(1));

#else

// give the worker threads some slack to make progress when their queues reached a soft max size
if (min_todo > flag_max_queue && flag_max_queue > 0)
std::this_thread::sleep_for(std::chrono::milliseconds(1));

// submit job to worker, do not loop
iworker->submit_job(pathname, cost, sync.next);
break;

#endif
}

++sync.next;
Expand Down Expand Up @@ -4535,7 +4531,7 @@ int main(int argc, const char **argv)
if (!flag_no_messages && Static::warnings > 0)
abort("option -Q: warnings are present, specify -s to ignore");

// queue more files than we queue for more optimized searching by default
// increase worker threads queue
flag_max_queue = 65536;

// -Q: TUI query mode
Expand Down

0 comments on commit d736d6f

Please sign in to comment.