Boost logo

Boost Users :

Subject: Re: [Boost-users] why boost is so slow for file search?
From: Igor R (boost.lists_at_[hidden])
Date: 2012-06-13 14:18:46


> I have 2 functions for read files list in one directory. One uses Win32 and
> one uses boost:

FWIW, directory_iterator_increment() look like this:

  void directory_iterator_increment(directory_iterator& it,
    system::error_code* ec)
  {
    BOOST_ASSERT_MSG(it.m_imp.get(), "attempt to increment end iterator");
    BOOST_ASSERT_MSG(it.m_imp->handle != 0, "internal program error");

    path::string_type filename;
    file_status file_stat, symlink_file_stat;
    system::error_code temp_ec;

    for (;;)
    {
      temp_ec = dir_itr_increment(it.m_imp->handle,
# if defined(BOOST_POSIX_API)
        it.m_imp->buffer,
# endif
        filename, file_stat, symlink_file_stat);

      if (temp_ec) // happens if filesystem is corrupt, such as on a
damaged optical disc
      {
        path error_path(it.m_imp->dir_entry.path().parent_path()); //
fix ticket #5900
        it.m_imp.reset();
        if (ec == 0)
          BOOST_FILESYSTEM_THROW(
            filesystem_error("boost::filesystem::directory_iterator::operator++",
              error_path,
              error_code(BOOST_ERRNO, system_category())));
        ec->assign(BOOST_ERRNO, system_category());
        return;
      }
      else if (ec != 0) ec->clear();

      if (it.m_imp->handle == 0) // eof, make end
      {
        it.m_imp.reset();
        return;
      }

      if (!(filename[0] == dot // !(dot or dot-dot)
        && (filename.size()== 1
          || (filename[1] == dot
            && filename.size()== 2))))
      {
        it.m_imp->dir_entry.replace_filename(
          filename, file_stat, symlink_file_stat);
        return;
      }
    }
  }

...and the inner dir_itr_increment() function involves the following:

  perms make_permissions(const path& p, DWORD attr)
  {
    perms prms = fs::owner_read | fs::group_read | fs::others_read;
    if ((attr & FILE_ATTRIBUTE_READONLY) == 0)
      prms |= fs::owner_write | fs::group_write | fs::others_write;
    if (BOOST_FILESYSTEM_STRICMP(p.extension().string().c_str(), ".exe") == 0
      || BOOST_FILESYSTEM_STRICMP(p.extension().string().c_str(), ".com") == 0
      || BOOST_FILESYSTEM_STRICMP(p.extension().string().c_str(), ".bat") == 0
      || BOOST_FILESYSTEM_STRICMP(p.extension().string().c_str(), ".cmd") == 0)
      prms |= fs::owner_exe | fs::group_exe | fs::others_exe;
    return prms;
  }

...where each of the 4 comparisons invokes conversion from wchar_t* to
std::string.

So, there's obviously a lot of overhead, but the question is whether
it's really a bottleneck in a real-life application.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net