Kaydet (Commit) 0d04315c authored tarafından Noel Grandin's avatar Noel Grandin

tdf#67538 XTypeDetection::queryTypeByDescriptor poor performance, part4

WPXSvInputStreamImpl was hammering on getFilePos pretty hard, and
getFilePos uses a mutex, which is slow when it is called from every
single read. So switch to using std::atomic to access position.

This is specifically fixing the performance of queryTypeByDescriptor
when called from a basic macro on a local test file.

This takes my test macro from 8s to 4s.

Change-Id: Iab707a374359e2ee0e92425b2d9a903d67cb53d4
Reviewed-on: https://gerrit.libreoffice.org/73377
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 501b935d
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "unixerrnostring.hxx" #include "unixerrnostring.hxx"
#include <algorithm> #include <algorithm>
#include <atomic>
#include <cassert> #include <cassert>
#include <limits> #include <limits>
...@@ -84,7 +85,8 @@ struct FileHandle_Impl ...@@ -84,7 +85,8 @@ struct FileHandle_Impl
sal_uInt64 m_size; /*< file size */ sal_uInt64 m_size; /*< file size */
off_t m_offset; /*< physical offset from begin of file */ off_t m_offset; /*< physical offset from begin of file */
off_t m_fileptr; /*< logical offset from begin of file */ // m_fileptr is hit hard in some situations, where the overhead of a mutex starts to show up, so use an atomic
std::atomic<off_t> m_fileptr; /*< logical offset from begin of file */
off_t m_bufptr; /*< buffer offset from begin of file */ off_t m_bufptr; /*< buffer offset from begin of file */
size_t m_buflen; /*< buffer filled [0, m_bufsiz - 1] */ size_t m_buflen; /*< buffer filled [0, m_bufsiz - 1] */
...@@ -224,7 +226,7 @@ size_t FileHandle_Impl::getpagesize() ...@@ -224,7 +226,7 @@ size_t FileHandle_Impl::getpagesize()
sal_uInt64 FileHandle_Impl::getPos() const sal_uInt64 FileHandle_Impl::getPos() const
{ {
return sal::static_int_cast< sal_uInt64 >(m_fileptr); return sal::static_int_cast< sal_uInt64 >(m_fileptr.load());
} }
void FileHandle_Impl::setPos(sal_uInt64 uPos) void FileHandle_Impl::setPos(sal_uInt64 uPos)
...@@ -1421,7 +1423,7 @@ oslFileError SAL_CALL osl_getFilePos(oslFileHandle Handle, sal_uInt64* pPos) ...@@ -1421,7 +1423,7 @@ oslFileError SAL_CALL osl_getFilePos(oslFileHandle Handle, sal_uInt64* pPos)
if ((!pImpl) || ((pImpl->m_kind == FileHandle_Impl::KIND_FD) && (pImpl->m_fd == -1)) || (!pPos)) if ((!pImpl) || ((pImpl->m_kind == FileHandle_Impl::KIND_FD) && (pImpl->m_fd == -1)) || (!pPos))
return osl_File_E_INVAL; return osl_File_E_INVAL;
FileHandle_Impl::Guard lock(&(pImpl->m_mutex)); // no need to lock because pos is atomic
*pPos = pImpl->getPos(); *pPos = pImpl->getPos();
return osl_File_E_None; return osl_File_E_None;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "file_url.hxx" #include "file_url.hxx"
#include "file_error.hxx" #include "file_error.hxx"
#include <atomic>
#include <cassert> #include <cassert>
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
...@@ -60,7 +61,8 @@ struct FileHandle_Impl ...@@ -60,7 +61,8 @@ struct FileHandle_Impl
sal_uInt64 m_size; /*< file size */ sal_uInt64 m_size; /*< file size */
LONGLONG m_offset; /*< physical offset from begin of file */ LONGLONG m_offset; /*< physical offset from begin of file */
LONGLONG m_filepos; /*< logical offset from begin of file */ // m_filepos is hit hard in some situations, where the overhead of a mutex starts to show up, so use an atomic
std::atomic<LONGLONG> m_filepos; /*< logical offset from begin of file */
LONGLONG m_bufptr; /*< buffer offset from begin of file */ LONGLONG m_bufptr; /*< buffer offset from begin of file */
SIZE_T m_buflen; /*< buffer filled [0, m_bufsiz - 1] */ SIZE_T m_buflen; /*< buffer filled [0, m_bufsiz - 1] */
...@@ -185,7 +187,7 @@ SIZE_T FileHandle_Impl::getpagesize() ...@@ -185,7 +187,7 @@ SIZE_T FileHandle_Impl::getpagesize()
sal_uInt64 FileHandle_Impl::getPos() const sal_uInt64 FileHandle_Impl::getPos() const
{ {
return sal::static_int_cast< sal_uInt64 >(m_filepos); return sal::static_int_cast< sal_uInt64 >(m_filepos.load());
} }
oslFileError FileHandle_Impl::setPos(sal_uInt64 uPos) oslFileError FileHandle_Impl::setPos(sal_uInt64 uPos)
...@@ -946,8 +948,9 @@ oslFileError SAL_CALL osl_getFilePos(oslFileHandle Handle, sal_uInt64 *pPos) ...@@ -946,8 +948,9 @@ oslFileError SAL_CALL osl_getFilePos(oslFileHandle Handle, sal_uInt64 *pPos)
if ((!pImpl) || !IsValidHandle(pImpl->m_hFile) || (!pPos)) if ((!pImpl) || !IsValidHandle(pImpl->m_hFile) || (!pPos))
return osl_File_E_INVAL; return osl_File_E_INVAL;
FileHandle_Impl::Guard lock(&(pImpl->m_mutex)); // no need to lock because pos is atomic
*pPos = pImpl->getPos(); *pPos = pImpl->getPos();
return osl_File_E_None; return osl_File_E_None;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment