From db442fb0c1b994cad10f021f30083f98b5dc7bd0 Mon Sep 17 00:00:00 2001 From: Eric Cornelissen Date: Sun, 3 Feb 2019 23:31:22 +0200 Subject: [PATCH] Improve search performance (#1170) * Improve performance of search on website By reducing the number of times a search query loops over all icons or all icons that match the search query (from 3 to 1 and 2 to 0 respectively) the search on simpleicons.org should now be noticeably faster (if it was slow before). Especially in conjunction with #1169. This was achieved by utilizing CSS (which operates faster then plain JavaScript) to do most of the heavy lifting. A class on now dictates the order of the icons rather then a JavaScript for-loop (found in the removed function `orderIcons`). It was also achieved by more cleverly utilizing the fuzzy search logic and recognizing that the CSS `order` property also works if number are not consecutive. Less relevant numbers will have a higher value assigned by fuzzy search, which is what the `order`-value of the icon will become, removing the need for sorting and an additional loop. Some resources that helped me: - https://css-tricks.com/css-attr-function-got-nothin-custom-properties/ - https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables Specifically the "Values in JavaScript" section * * * One unrelated change in stylesheet.css where 2 separate rulesets for .grid-item__link have been merged. * Simplify script with regard to button states * Reduce complexity of `previousQuery` variables --- index.html | 6 ++-- site_script.js | 89 ++++++++++++++++++-------------------------------- stylesheet.css | 31 ++++++++++++++---- 3 files changed, 59 insertions(+), 67 deletions(-) diff --git a/index.html b/index.html index 748f6624..f0a8bc77 100644 --- a/index.html +++ b/index.html @@ -216,7 +216,7 @@ Sort by color Sort alphabetically - Sort by relevance + Sort by relevance