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

Persist a subset of IdMap #10347

Merged
merged 7 commits into from
Jul 8, 2024
Merged

Conversation

4e6
Copy link
Contributor

@4e6 4e6 commented Jun 23, 2024

Pull Request Description

close #9257

Changelog:

  • update: Store in the file only the subset of IdMap containing the IDs used in the metadata section on the 2nd line. The full IdMap is transmitted as a parameter of the text/applyEdit request.

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.

@4e6 4e6 added the CI: No changelog needed Do not require a changelog entry for this PR. label Jun 23, 2024
@4e6 4e6 self-assigned this Jun 23, 2024
@4e6 4e6 marked this pull request as ready for review June 25, 2024 16:36
@4e6
Copy link
Contributor Author

4e6 commented Jun 25, 2024

Please QA

}
const newMetadataJson = newMetadata && json.stringify(metadataToPersist)
const idMapToPersist =
newIdMap &&
Copy link
Contributor

@kazcw kazcw Jun 25, 2024

Choose a reason for hiding this comment

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

This condition is no longer accurate: A new idMapToPersist needs to be computed if the ID map changes or if the metadata changes.

Copy link
Contributor Author

@4e6 4e6 Jun 26, 2024

Choose a reason for hiding this comment

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

If the metadata line changes, the IdMap will be recomputed as well. And if the metadata was changed without changing the IDs, we don't need to edit the IdMap section.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the metadata line changes, the IdMap will be recomputed as well.

I don't see this being enforced in the ydoc-server. If you mean it will be recomputed at the same time in the GUI, the ydoc-server should not depend on that.

When adding a new node, first the new node is committed then its position is computed. In the interim, the node usually doesn't have any non-default metadata; if we are always writing node metadata at the same time that a node is added, that's an inefficiency we should be able to fix in the GUI without the ydoc-server causing data loss.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is indeed a problem. There needs to be a check if newMetadata contains a new key. At the minimum, This could be (newIdMap || newMetadata) &&, effectively always writing ID Map when any metadata changes. That could be further optimized later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can see that applyDocumentUpdates

const { newCode, newIdMap, newMetadata } = applyDocumentUpdates(
this.doc,
synced,
moduleUpdate,
)

recomputes IdMap from the root AST
const syncModule = new MutableModule(doc.ydoc)
const root = syncModule.root()
assert(root != null)
if (codeChanged || idsChanged || synced.idMapJson == null) {
const { code, info } = print(root)
if (codeChanged) newCode = code
newIdMap = spanMapToIdMap(info)
}

or am I reading that wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

The condition codeChanged || idsChanged || synced.idMapJson == null can still be false when existing metadata structure updates. In that situation a new ID will have to be stored while no code was actually changed.

Currently, all metadata is written on expressions that also happen to be node roots, so it kinda works out. But this is not a limitation of the system that we are willing to have, since we are soon going to add metadata to individual expressions. That will be needed to store persistent widget state. Those expressions will already exist when we adjust the widget data, effectively sending a delaying metadata update without any code changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

  • the direction looks good
  • having some unit test would make the change more robust for the future
  • what is the effect on size of IdMap of some well known example?

app/gui2/shared/languageServerTypes.ts Show resolved Hide resolved
@enso-bot enso-bot bot mentioned this pull request Jun 27, 2024
5 tasks
@4e6 4e6 added the CI: Ready to merge This PR is eligible for automatic merge label Jul 8, 2024
@mergify mergify bot merged commit b2c4559 into develop Jul 8, 2024
37 checks passed
@mergify mergify bot deleted the wip/db/9257-remove-idmap-from-source-file branch July 8, 2024 17:59
hubertp added a commit that referenced this pull request Jul 22, 2024
jdunkerley pushed a commit that referenced this pull request Jul 22, 2024
This reverts commit b2c4559.

Merging as just failing the Vector tests addressed in another PR.
4e6 added a commit that referenced this pull request Jul 27, 2024
mergify bot pushed a commit that referenced this pull request Jul 29, 2024
Re-enable the IdMap optimization. It was reverted in #10626

#10674 Fixed the issue with loading dynamic widgets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove IdMap from source file.
4 participants