sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Find previous is slower than find next

Open z-aki opened this issue 4 years ago • 3 comments

Description

In a file with some rare characters, find previous freezes and takes a long time while find next is instantaneous.

Steps to reproduce

  • Run the program at the end to make such a file. (200 MB)
  • Open it, and find "a" without regex or case matching. Just case insensitive string search.
  • Experiment with enter & shift+enter.

Expected behavior

Equally performant ?

Actual behavior

Shift+enter is slower than enter.

Environment

Build 3211 macOS Mojave.


#include <iostream>
#include <fstream>
#include <ostream>
#include <string>

const int TOTAL{1000 * 1000 * 50};
const std::string STORAGE{"bcdefghijklmnopqrstuvwxyz1234567890"};  // 26 - 1  + 10
const size_t SIZE{STORAGE.size()};

int main(int argc, const char *argv[])
{
  std::ofstream outfile_s{"a.txt"};
  if (outfile_s.bad()) {
    std::cerr << "Couldn't open file." << std::endl;
    return -1;
  }
  outfile_s << "a\n";
  for (int i = 0; i < TOTAL; i++) {
    outfile_s << STORAGE[rand() % SIZE] << "\n";
  }
  outfile_s << "a\n";
  for (int i = 0; i < TOTAL; i++) {
    outfile_s << STORAGE[rand() % SIZE] << "\n";
  }
  return 0;
}

z-aki avatar Aug 27 '20 17:08 z-aki

If I am remembering the implementation correctly, I believe this has do to with how backwards searches are performed. To find the previous match it searches from the beginning of the buffer to the current match and then selects the final match.

wbond avatar Sep 09 '20 01:09 wbond

I just want to add and confirm about this issue. I tested with the 5million lines CSV data from here: link from EForExcel.com

I tested in Sublime Safe Mode, vanilla BBEdit, minimal configuration (no plugin) terminal vim, and vanilla terminal emacs.

It's not quite a fair comparison, but BBEdit, terminal vim, and terminal emacs (haven't tried GUI Emacs) can perform backward search (and even replace) in less than 3 seconds.

ybbond avatar May 26 '21 08:05 ybbond

Do we expect any fix for this issue? it seems to be an old one looking at the date

humam2104 avatar Jun 11 '21 06:06 humam2104