From d8812a7f208b2d1a4a0b5898d3f00ab3f4482d4c Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 21 Mar 2017 23:15:58 -0700 Subject: [PATCH] Perf get blocks (#678) * improve perf of getBlocks and getInlines * add getBlocksByType, getInlinesByType, fix getMarksByType --- benchmark/fixtures/models/get-blocks/index.js | 10 + .../fixtures/models/get-blocks/input.yaml | 683 ++++++++++++++++++ .../fixtures/models/get-inlines/index.js | 10 + .../fixtures/models/get-inlines/input.yaml | 683 ++++++++++++++++++ src/models/node.js | 93 ++- 5 files changed, 1463 insertions(+), 16 deletions(-) create mode 100644 benchmark/fixtures/models/get-blocks/index.js create mode 100644 benchmark/fixtures/models/get-blocks/input.yaml create mode 100644 benchmark/fixtures/models/get-inlines/index.js create mode 100644 benchmark/fixtures/models/get-inlines/input.yaml diff --git a/benchmark/fixtures/models/get-blocks/index.js b/benchmark/fixtures/models/get-blocks/index.js new file mode 100644 index 000000000..2de37c1e4 --- /dev/null +++ b/benchmark/fixtures/models/get-blocks/index.js @@ -0,0 +1,10 @@ + +import { __clear } from '../../../../lib/utils/memoize' + +export default function (state) { + state.document.getBlocks() +} + +export function after() { + __clear() +} diff --git a/benchmark/fixtures/models/get-blocks/input.yaml b/benchmark/fixtures/models/get-blocks/input.yaml new file mode 100644 index 000000000..b510137eb --- /dev/null +++ b/benchmark/fixtures/models/get-blocks/input.yaml @@ -0,0 +1,683 @@ +nodes: +- kind: block + type: paragraph + nodes: + - kind: block + type: paragraph + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: 'This is editable ' + - text: 'rich' + marks: + - type: bold + - text: ' text, ' + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: 'much' + marks: + - type: italic + - text: ' better than a ' + - text: '