Skip to content

Commit 91dec4e

Browse files
committed
Improvement #7382 - Performance improvement for BLOB copying.
1 parent b3f0469 commit 91dec4e

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/jrd/blb.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -2151,11 +2151,13 @@ blb* blb::copy_blob(thread_db* tdbb, const bid* source, bid* destination,
21512151
}
21522152

21532153
HalfStaticArray<UCHAR, 2048> buffer;
2154-
UCHAR* buff = buffer.getBuffer(input->blb_max_segment);
2154+
UCHAR* buff = buffer.getBuffer(input->isSegmented() ?
2155+
input->blb_max_segment :
2156+
MIN(input->blb_length, 32768));
21552157

21562158
while (true)
21572159
{
2158-
const USHORT length = input->BLB_get_segment(tdbb, buff, input->blb_max_segment);
2160+
const USHORT length = input->BLB_get_segment(tdbb, buff, buffer.getCapacity());
21592161
if (input->blb_flags & BLB_eof) {
21602162
break;
21612163
}

src/jrd/blob_filter.cpp

+39-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424

2525
#include "firebird.h"
26+
#include <algorithm>
27+
#include <iterator>
2628
#include <string.h>
2729
#include <stdio.h>
2830

@@ -60,6 +62,7 @@ static const FPTR_BFILTER_CALLBACK filters[] =
6062
filter_trans,
6163
filter_trans, // should be filter_external_file
6264
filter_debug_info
65+
// Add new entries to isInternalFilter
6366
};
6467

6568

@@ -69,6 +72,26 @@ static void open_blob(thread_db*, jrd_tra*, BlobControl**, bid*,
6972
USHORT, BlobFilter*);
7073

7174

75+
// Check if this is an internal filter.
76+
static bool isInternalFilter(BlobControl* control)
77+
{
78+
const auto routine = control->ctl_source;
79+
const bool isInternal =
80+
routine == filter_text ||
81+
routine == filter_transliterate_text ||
82+
routine == filter_blr ||
83+
routine == filter_acl ||
84+
routine == filter_runtime ||
85+
routine == filter_format ||
86+
routine == filter_trans ||
87+
routine == filter_debug_info;
88+
89+
fb_assert(isInternal == (std::find(std::begin(filters), std::end(filters), routine) != std::end(filters)));
90+
91+
return isInternal;
92+
}
93+
94+
7295
void BLF_close_blob(thread_db* tdbb, BlobControl** filter_handle)
7396
{
7497
/**************************************
@@ -170,9 +193,14 @@ ISC_STATUS BLF_get_segment(thread_db* tdbb,
170193

171194
ISC_STATUS status;
172195

173-
START_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message.c_str())
174-
status = (*control->ctl_source) (isc_blob_filter_get_segment, control);
175-
END_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message.c_str())
196+
if (isInternalFilter(control))
197+
status = (*control->ctl_source)(isc_blob_filter_get_segment, control);
198+
else
199+
{
200+
START_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message.c_str())
201+
status = (*control->ctl_source)(isc_blob_filter_get_segment, control);
202+
END_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message.c_str())
203+
}
176204

177205
if (!status || status == isc_segment)
178206
*length = control->ctl_segment_length;
@@ -284,9 +312,14 @@ void BLF_put_segment(thread_db* tdbb,
284312

285313
ISC_STATUS status;
286314

287-
START_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message.c_str())
288-
status = (*control->ctl_source) (isc_blob_filter_put_segment, control);
289-
END_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message.c_str())
315+
if (isInternalFilter(control))
316+
status = (*control->ctl_source)(isc_blob_filter_put_segment, control);
317+
else
318+
{
319+
START_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message.c_str())
320+
status = (*control->ctl_source)(isc_blob_filter_put_segment, control);
321+
END_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message.c_str())
322+
}
290323

291324
if (status)
292325
{

0 commit comments

Comments
 (0)