Skip to content

Refactor find in terms of clean Record API#10929

Merged
sholderbach merged 3 commits intonushell:mainfrom
sholderbach:find-record
Nov 8, 2023
Merged

Refactor find in terms of clean Record API#10929
sholderbach merged 3 commits intonushell:mainfrom
sholderbach:find-record

Conversation

@sholderbach
Copy link
Copy Markdown
Member

Description

Rewrite find internals with the same principles as in #10927.

Here we can remove an unnecessary lookup accross all columns when not narrowing find to particular columns

  • Change find internal fns to use iterators
  • Remove unnecessary quadratic lookup in find
  • Refactor find record highlight logic

User-Facing Changes

Should provide a small speedup when not providing find --columns

Tests + Formatting

(-)

`record_matches_term()` was checking if the record columns contain the
record columns if not narrowed to specific columns. Don't do that and
only perform the `contains()` check if given a set of columns.
- Remove quadratic lookup if not given narrowing columns
- Use a single `.iter_mut` loop to perform the highlighting instead of
iter(tools) chaining.
@sholderbach
Copy link
Copy Markdown
Member Author

Performance measured with

1..1000 | each { scope commands | timeit { find 42 } } | math avg

as scope commands returns a reasonably large known table with a decent number of columns.

Before (base commit)

14ms 215µs 420ns

With this

13ms 329µs 18ns

@sholderbach sholderbach merged commit f45aed2 into nushell:main Nov 8, 2023
@sholderbach sholderbach deleted the find-record branch November 8, 2023 00:06
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
# Description
Rewrite `find` internals with the same principles as in nushell#10927.

Here we can remove an unnecessary lookup accross all columns when not
narrowing find to particular columns

- Change `find` internal fns to use iterators
- Remove unnecessary quadratic lookup in `find`
- Refactor `find` record highlight logic
# User-Facing Changes
Should provide a small speedup when not providing `find --columns`

# Tests + Formatting
(-)
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
Rewrite `find` internals with the same principles as in nushell#10927.

Here we can remove an unnecessary lookup accross all columns when not
narrowing find to particular columns

- Change `find` internal fns to use iterators
- Remove unnecessary quadratic lookup in `find`
- Refactor `find` record highlight logic
# User-Facing Changes
Should provide a small speedup when not providing `find --columns`

# Tests + Formatting
(-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant