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

Add potential fix for increasing map size bug #3699

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

filipre
Copy link

@filipre filipre commented Feb 9, 2023

This PR fixes #3448 and jupyter-widgets/ipyleaflet#1098

Solution proposed by @maartenbreddels here: #3448 (comment)

I used binder and the code in the original issue to check if the file size still increases. It looks fine to me.

Current: 0.html: 0.01361083984375 MB
Current: 1.html: 0.01361083984375 MB
Current: 2.html: 0.01361083984375 MB
Current: 3.html: 0.01361083984375 MB
Current: 4.html: 0.01361083984375 MB
Current: 5.html: 0.01361083984375 MB
...
Current: 195.html: 0.01361083984375 MB
Current: 196.html: 0.01361083984375 MB
Current: 197.html: 0.01361083984375 MB
Current: 198.html: 0.01361083984375 MB
Current: 199.html: 0.01361083984375 MB

@github-actions
Copy link

github-actions bot commented Feb 9, 2023

Binder 👈 Launch a binder notebook on branch filipre/ipywidgets/fix-increasing-html-size

@filipre filipre marked this pull request as ready for review February 9, 2023 10:44
Copy link
Member

@maartenbreddels maartenbreddels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, for taking this on. Left a comment for you, let me know what you think.

Comment on lines 304 to 318

if kwargs.get("state") is None:
state = dependency_state(views, drop_defaults=kwargs.get("drop_defaults"))
else:
state = kwargs["state"]

snippet = embed_snippet(
views,
drop_defaults=kwargs.get("drop_defaults", True),
state=state,
indent=kwargs.get("indent", 2),
embed_url=kwargs.get("embed_url", None),
requirejs=kwargs.get("requirejs", True),
cors=kwargs.get("cors", True)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to explicitly add the arguments (just copy-paste them from embed_snippet).
Would also be good to update the docstring, which is not incorrect (the behaviour of state=None is different).
Maybe this should be an opt-in for backward compatibility. (state_tree_shake=False maybe?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the correct behaviour is dependency_state and not get_manager_state, then I think the backwards compatibility relies on a bug 🤔 What do you think about passing a string instead, e.g. state="all" to include everything instead of having an argument toggle that switches between dependencies and full state (and only if state is None)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the documentation and also used a string to toggle between the modes:

state is None or equals "dependent": function will use dependency_state:

Current: 0.html: 0.0067501068115234375 MB
Current: 1.html: 0.0067501068115234375 MB
Current: 2.html: 0.0067501068115234375 MB
Current: 3.html: 0.0067501068115234375 MB
Current: 4.html: 0.0067501068115234375 MB
...

state equals "complete": function will use get_manager_state:

Current: 0.html: 0.006749153137207031 MB
Current: 1.html: 0.012719154357910156 MB
Current: 2.html: 0.01868915557861328 MB
Current: 3.html: 0.024659156799316406 MB
Current: 4.html: 0.03062915802001953 MB
...

state is a dictionary: function will use passed state direclty

Current: 0.html: 0.0007772445678710938 MB
Current: 1.html: 0.0007772445678710938 MB
Current: 2.html: 0.0007772445678710938 MB
Current: 3.html: 0.0007772445678710938 MB
Current: 4.html: 0.0007772445678710938 MB
...

Could you take another look on the code?

if state is None or state == "dependent":
state = dependency_state(views, drop_defaults=drop_defaults)
elif state == "complete":
state = Widget.get_manager_state(drop_defaults=drop_defaults, widgets=None)['state']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to move this logic into embed_data instead? Then we get support for these enums in more functions (and we also get to reuse the docstrings 😄).

"""
snippet = embed_snippet(views, **kwargs)

if state is None or state == "dependent":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the default (None case) is the most controversial here, as it is strictly speaking backwards incompatible. There might be a case for calling it a workaround for the poor GC of ipywidgets, but making this change should at least have some more eyes on it before merging.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your argument and it's difficult for me to estimate how much of an impact this change would have to other projects. Coming from ipyleaflet, it just looks like a bug to me and then I'd argue, that backwards compatibility should not rely on bugs. However, if other people really need the whole state and really have that implementation assumption as well, then I agree, we should stay backwards compatible as well. What do you think?

Your solution definelty will work in the end but as a user, it's not so clear to me when I'd use the dependent state and when the complete.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of agree it is a bug, we didn't implement this feature for nothing. I think this was the intended behavior, but yeah, fixing a bug can be considered a breaking change :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See original discussion here: #1387 (comment)

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.

Possible bug with ipywidgets or gmaps, not sure
3 participants