Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get: Optimize performance #1031

Merged
merged 1 commit into from
Jan 9, 2025
Merged

Conversation

Emiyaaaaa
Copy link
Collaborator

@Emiyaaaaa Emiyaaaaa commented Jan 3, 2025

Limit suggestions to 'a.b.c' to optimize performance. That is enough for most cases.

@marcomuser
Copy link

Even with this change it will remain configurable by passing in Paths generic with a higher maxRecursionDepth, right? I need a higher maxRecursionDepth than 2. :)

@sindresorhus
Copy link
Owner

This also should be done in v5. And if we decide to do it, it must be possible to increase it. I'm just wondering whether the performance increase is worth the inconvenience of potentially not having all things work directly with Get without having to set an option.

@som-sm
Copy link
Collaborator

som-sm commented Jan 9, 2025

This is not a breaking change like #1029 since it just affects the autocomplete. The second type argument continues to accept any string, just the autocomplete suggestions reduce to only depth: 2, which is fine IMO.


Current behaviour:

type Test = Get<{a: {b: {c: {d: string}}}}, 'a.b.d.e.f.g.h.i.j'>; // Valid
image

Updated behaviour:

type Test = Get<{a: {b: {c: {d: string}}}}, 'a.b.d.e.f.g.h.i.j'>; // Still Valid

Just the autocomplete suggestions reduce:
image

@som-sm
Copy link
Collaborator

som-sm commented Jan 9, 2025

I'm just wondering whether the performance increase is worth the inconvenience of potentially not having all things work directly with Get without having to set an option.

@sindresorhus I think there's some confusion, everything will still continue to work, right? The second type argument still effectively accepts any string.


And if we decide to do it, it must be possible to increase it.

Not sure, if we really need an option to control the autocomplete behaviour. The way it's used in the JSDoc example (which I feel is how this would mostly be used), the autocomplete is anyways not dependent on our code but on user's code.

// `Path` here decides the autocomplete behaviour
const get = <BaseType, Path extends string | readonly string[]>(object: BaseType, path: Path): Get<BaseType, Path> =>
	lodash.get(object, path);

@sindresorhus
Copy link
Owner

Ah, I didn't realize this is only about auto-complete. Then it's totally fine.

@sindresorhus sindresorhus changed the title Optimize Get performance Get: Optimize performance Jan 9, 2025
@sindresorhus sindresorhus merged commit cfb5947 into sindresorhus:main Jan 9, 2025
12 checks passed
@Emiyaaaaa
Copy link
Collaborator Author

Even with this change it will remain configurable by passing in Paths generic with a higher maxRecursionDepth, right? I need a higher maxRecursionDepth than 2. :)

sure

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.

4 participants