Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Performance improvements #220

Open
Open
Labels
@romulof

Description

Motivation

Performance

Current behavior

Each time I pass a path it needs to be parsed and the queried for all possible matching items

Desired behavior

Be able to create and object for a path that stores the parsed query and allows me to execute it many times, skipping the overhead of path parsing. Additionally it would be good to specify the search limit.

Example:

const bookTitlePath = new JSONPath<string>('$..book[*].title');
const bookPricePath = new JSONPath<number>('$..book[*].price');
function getFirstBook(storeData: object): string {
 return bookTitlePath.value(storeData); // Returns first match
}
// Consider books are in desc order of sales
function getAveragePriceOfBestSellingBooks(storeData: object): number {
 const prices: number[] = bookPricePath.query(storeData, 10); // Get up to 10 elements
 // The only viable usage of reduce 😬 
 return prices.reduce((total, price) => total + price, 0) / prices.length;
}

Alternatives considered

Could not find any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /