Guo Xiang Tan
053cbe3112
PERF: Limit characters used to generate headline for search blurb.
We determined using the following benchmark script that limiting to 2500 chars would mean a maximum of
25ms spent generating headlines.
```
require 'benchmark/ips'
string = <<~STRING
Far far away, behind the word mountains...
STRING
def sql_excerpt(string, l = 1000000)
DB.query_single(<<~SQL)
SELECT TS_HEADLINE('english', left('#{string}', #{l}), PLAINTO_TSQUERY('mountains'))
SQL
end
def ruby_excerpt(string)
output = DB.query_single("SELECT '#{string}'")[0]
Search::GroupedSearchResults::TextHelper.excerpt(output, 'mountains', radius: 100)
end
puts "Ruby Excerpt: #{ruby_excerpt(string)}"
puts "SQL Excerpt: #{sql_excerpt(string)}"
puts
Benchmark.ips do |x|
x.time = 10
[1000, 2500, 5000, 10000, 20000, 50000].each do |l|
short_string = string[0..l]
x.report("ts_headline excerpt #{l}") do
sql_excerpt(short_string, l)
end
x.report("actionview excerpt #{l}") do
ruby_excerpt(short_string)
end
end
x.compare!
end
```
```
actionview excerpt 1000: 20570.7 i/s
actionview excerpt 2500: 17863.1 i/s - 1.15x (± 0.00) slower
actionview excerpt 5000: 14228.9 i/s - 1.45x (± 0.00) slower
actionview excerpt 10000: 10906.2 i/s - 1.89x (± 0.00) slower
actionview excerpt 20000: 6255.0 i/s - 3.29x (± 0.00) slower
ts_headline excerpt 1000: 4337.5 i/s - 4.74x (± 0.00) slower
actionview excerpt 50000: 3222.7 i/s - 6.38x (± 0.00) slower
ts_headline excerpt 2500: 2240.4 i/s - 9.18x (± 0.00) slower
ts_headline excerpt 5000: 1258.7 i/s - 16.34x (± 0.00) slower
ts_headline excerpt 10000: 667.2 i/s - 30.83x (± 0.00) slower
ts_headline excerpt 20000: 348.7 i/s - 58.98x (± 0.00) slower
ts_headline excerpt 50000: 131.9 i/s - 155.91x (± 0.00) slower
```
2020-08-07 14:36:52 +08:00
..
2020-07-27 10:23:54 +10:00
2019-10-02 14:01:53 +10:00
2020-07-27 10:23:54 +10:00
2020-07-27 10:23:54 +10:00
2020-06-23 17:10:56 +10:00
2020-07-27 13:23:17 -04:00
2020-07-14 12:36:19 -04:00
2019-10-02 14:01:53 +10:00
2020-08-04 14:19:57 +10:00
2019-10-02 14:01:53 +10:00
2020-08-03 14:21:33 +08:00
2020-05-15 14:23:27 +08:00
2020-07-27 10:23:54 +10:00
2020-08-06 09:46:17 -04:00
2019-10-14 12:57:33 +05:30
2019-04-30 10:27:42 +10:00
2020-04-08 12:42:28 +10:00
2020-06-04 10:44:54 -04:00
2020-08-06 09:46:17 -04:00
2020-05-26 14:53:32 -04:00
2020-03-11 13:30:45 +00:00
2020-07-27 10:23:54 +10:00
2020-04-02 18:37:45 +01:00
2020-07-24 17:19:21 +08:00
2020-05-14 20:10:59 -06:00
2019-04-30 10:27:42 +10:00
2019-12-03 10:05:53 +01:00
2019-10-01 12:04:39 -04:00
2020-03-10 22:13:17 +01:00
2019-04-30 10:27:42 +10:00
2020-08-05 12:14:59 +01:00
2020-07-27 10:23:54 +10:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-10-16 14:28:04 -04:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2020-08-06 09:46:17 -04:00
2020-06-23 12:09:04 +08:00
2020-07-14 16:15:58 +08:00
2020-07-21 21:02:01 +05:30
2020-07-24 17:19:21 +08:00
2019-12-03 10:05:53 +01:00
2020-03-10 22:13:17 +01:00
2019-04-30 10:27:42 +10:00
2020-07-24 17:19:21 +08:00
2019-04-30 10:27:42 +10:00
2020-05-05 13:46:57 +10:00
2019-04-30 10:27:42 +10:00
2019-04-30 10:27:42 +10:00
2019-05-28 11:33:08 +10:00
2019-05-07 13:12:20 +10:00
2020-07-27 10:23:54 +10:00
2019-04-30 10:27:42 +10:00
2019-04-30 10:27:42 +10:00
2019-04-30 10:27:42 +10:00
2020-07-27 10:23:54 +10:00
2019-04-30 10:27:42 +10:00
2020-03-26 17:36:52 +11:00
2019-04-30 10:27:42 +10:00
2020-06-03 15:59:19 -06:00
2019-04-30 10:27:42 +10:00
2020-07-27 10:23:54 +10:00
2020-05-06 22:59:07 +02:00
2019-10-02 14:01:53 +10:00
2019-04-30 10:27:42 +10:00
2019-10-02 14:01:53 +10:00
2020-01-21 11:12:00 -05:00
2019-04-30 10:27:42 +10:00
2020-07-27 10:23:54 +10:00
2019-10-16 14:28:04 -04:00
2019-04-30 10:27:42 +10:00
2019-04-30 10:27:42 +10:00
2019-06-07 01:26:06 +02:00
2020-07-22 11:42:15 -03:00
2020-07-29 09:43:32 +10:00
2020-07-28 12:06:15 +10:00
2019-10-02 14:01:53 +10:00
2019-05-07 13:12:20 +10:00
2020-07-23 09:50:00 -04:00
2020-07-27 10:23:54 +10:00
2020-05-14 15:42:00 -07:00
2019-05-07 13:12:20 +10:00
2019-12-03 10:05:53 +01:00
2019-11-27 16:11:49 +11:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-12-11 11:26:52 -08:00
2020-07-29 10:31:55 +01:00
2019-05-07 13:12:20 +10:00
2020-08-07 14:36:52 +08:00
2019-11-11 11:18:12 +11:00
2019-05-13 09:31:32 +08:00
2020-07-27 10:23:54 +10:00
2019-12-17 10:34:20 +10:00
2020-07-27 10:23:54 +10:00
2019-08-06 11:26:54 +01:00
2019-05-30 07:56:36 +08:00
2019-05-20 13:47:20 +02:00
2019-04-30 10:27:42 +10:00
2019-05-07 13:12:20 +10:00
2019-04-30 10:27:42 +10:00
2019-10-02 14:01:53 +10:00
2020-03-10 22:13:17 +01:00
2020-03-10 22:13:17 +01:00
2020-07-23 10:30:23 +10:00
2020-04-20 14:17:13 -04:00
2020-08-05 11:51:28 +10:00
2019-11-01 09:19:43 +10:00
2019-10-02 14:01:53 +10:00
2019-04-30 10:27:42 +10:00
2019-04-30 10:27:42 +10:00
2020-01-31 09:09:34 +10:00
2020-07-17 10:48:08 +01:00
2020-07-27 10:23:54 +10:00
2020-07-09 14:57:27 -04:00