-
Notifications
You must be signed in to change notification settings - Fork 201
Runtime: more efficient (space-wise) marshalling. #814
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
794b3e6
Runtime: more efficient (space-wise) marshalling.
corwin-of-amber af0903b
Runtime: added test for marshal.
corwin-of-amber 87085e9
Runtime: Use WeakMap in marshal.
corwin-of-amber 2709d6d
Runtime: support Marshal flags.
corwin-of-amber 9ddd401
tuning
hhugo e5d7cd3
comment
hhugo 68e11d7
more tuning.
corwin-of-amber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| (* Js_of_ocaml tests | ||
| * http://www.ocsigen.org/js_of_ocaml/ | ||
| * Copyright (C) 2019 Shachar Itzhaky | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, with linking exception; | ||
| * either version 2.1 of the License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| *) | ||
|
|
||
| (* https://github.com/ocsigen/js_of_ocaml/pull/814 *) | ||
|
|
||
| let%expect_test _ = | ||
| Util.compile_and_run | ||
| {| | ||
| type sign = SPlus | SMinus | ||
| type raw_numeral = int | ||
|
|
||
| type prim_token = | ||
| | Numeral of sign * raw_numeral | ||
| | String of string | ||
|
|
||
| type operator_token = Add | Sub | Times | PlusPlus | ||
|
|
||
| type expr = | ||
| | Literal of prim_token | ||
| | Op of operator_token * expr list | ||
|
|
||
| let write_out chan v = | ||
| let start = pos_out chan in | ||
| Marshal.to_channel chan v []; | ||
| pos_out chan - start | ||
|
|
||
| let write_out_noshare chan v = | ||
| let start = pos_out chan in | ||
| Marshal.to_channel chan v [Marshal.No_sharing]; | ||
| pos_out chan - start | ||
|
|
||
| let _ = | ||
| let tmp_filename = Filename.temp_file "out" "txt" in | ||
| let chan = open_out tmp_filename in | ||
| let v1 = Op (Add, [Literal (Numeral (SPlus, 5)); Literal (Numeral (SMinus, 7))]) in | ||
| let v2 = Op (Times, [v1; v1]) (* shared *) in | ||
| let v1_sz = write_out chan v1 in | ||
| let v2_sz = write_out chan v2 in | ||
| let v2_ns_sz = write_out_noshare chan v2 in | ||
| flush chan; | ||
| Format.printf "sizes = %d %d %d (|v2| %s |v2_ns|)\n%!" v1_sz v2_sz v2_ns_sz | ||
| (if v2_sz < v2_ns_sz then "<" else ">="); | ||
|
|
||
| let chan = open_in tmp_filename in | ||
| let v1' = Marshal.from_channel chan in | ||
| let v2' = Marshal.from_channel chan in | ||
| Format.printf "readback = %B %B\n%!" (v1 = v1') (v2 = v2') | ||
| |}; | ||
| [%expect {| | ||
| sizes = 33 40 51 (|v2| < |v2_ns|) | ||
| readback = true true |}] | ||
|
|
||
| (* https://github.com/ocsigen/js_of_ocaml/issues/359 *) | ||
|
|
||
| let%expect_test _ = | ||
| let module M = struct | ||
| type loop = {mutable pointer : loop option} | ||
|
|
||
| let l = {pointer = None} | ||
|
|
||
| let () = l.pointer <- Some l | ||
|
|
||
| let _ = | ||
| let s = Marshal.to_string l [] in | ||
| Format.printf "%d\n%S\n%!" (String.length s) s | ||
| end in | ||
| [%expect | ||
| {| | ||
| 24 | ||
| "\132\149\166\190\000\000\000\004\000\000\000\002\000\000\000\004\000\000\000\004\144\144\004\002" |}] | ||
|
|
||
| let%expect_test _ = | ||
| Util.compile_and_run | ||
| {| | ||
| type loop = { mutable pointer : loop option } | ||
| let l = { pointer = None } | ||
| let () = l.pointer <- Some l | ||
|
|
||
| let _ = | ||
| let s = Marshal.to_string l [] in | ||
| Format.printf "%d\n%S\n%!" (String.length s) s | ||
| |}; | ||
| [%expect | ||
| {| | ||
| 24 | ||
| "\132\149\166\190\000\000\000\004\000\000\000\002\000\000\000\004\000\000\000\004\144\144\004\002" |}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current test setup this code is never tested because the condition is always
false. 😞There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested the code manually.